package database;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import database.Dbconnect;
public class CreateQuery {
Connection conn;
public CreateQuery() throws ClassNotFoundException, SQLException, IOException {
conn=new Dbconnect().returnDatabaseConnection();
}
public int addNewLayertoDB(String feature_name,String shape,int Latitude , int Longitude , int feature_geom , String feature_details){
try {
PreparedStatement statement = null;
String table_name = feature_name + "_" + shape;
String query = "CREATE TABLE EtherMap "+table_name+" ("+ feature_name+" (20))";
statement = conn.prepareStatement(query);
statement.setString(1, feature_name);
statement.execute();
String squery = "ALTER TABLE EtherMap" +table_name+" ADD COLUMN geom int , ADD COLUMN shape character(10)";
return 1;
} catch (SQLException ex) {
return 0;
}
}
public void closeConn() throws SQLException {
if (conn != null) {
this.conn.close();
}
}
}
我可以将squery和查询变量分成一个查询吗?如果是,那么如何?如何将这个postgresql查询压缩到java中的一个语句中?
你是说'CREATE TABLE'和'ALTER TABLE'? – bluefoot 2011-03-14 15:26:56
只能显示**有问题的SQL语句吗?这会让试图帮助你的人更容易。 – 2011-03-14 15:28:51
对'PreparedStatement.setString'的调用在文本本身没有查询参数的情况下无法工作。你应该传递类似于''CREATE TABLE?(?VARCHAR(20),geom int,shape char(10))'',用?为您想要动态设置的每个值。 – 2011-03-14 15:29:57