我在java中使用jdbc创建了postgresql中的架构。它似乎工作正常,但我需要一个函数来创建模式,我想知道是否有可能创建一个名称通过变量的架构...这是我的类CreateSchema:在java中使用名称传递的名称创建架构
是否有可能?
String sql = "CREATE SCHEMA centro";
在这一行“centro”就像一个变量。
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
Class.forName("org.postgresql.Driver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Creating Schema...");
stmt = conn.createStatement();
String sql = "CREATE SCHEMA centro";
stmt.executeUpdate(sql);
System.out.println("Schema created successfully...");
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException se2) {
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException se) {
se.printStackTrace();
}
}
谢谢。
如果'串SCHEMANAME = “炫酷”'你是问,如果像'字符串SQL = “创建模式” + schemaName'.can做些什么呢? –
是的,这是我的问题 –
这就是你的答案然后:-) –