【发布时间】:2019-09-25 11:41:56
【问题描述】:
获取异常(SQL 语法错误)。
刚接触DB编程,到处找,但似乎无法确定,
我知道我在执行语句时遇到了一些问题,因为错误日志告诉我错误行是 -
Statement stmt= con.prepareStatement(sql);
方法:
public static void createTable(String name) {
String url= "jdbc:derby://localhost:1527/newDB;create=true";
try (Connection con=DriverManager.getConnection(url)){
String sql="create table "+name+" (ID int, Name varchar(20)";
Statement stmt= con.prepareStatement(sql);
stmt.executeUpdate(sql);
System.out.println("Table Created");
}catch (SQLException e) {
System.out.println("Table creation interupted");
e.printStackTrace();
}
}
一直在尝试各种方法来编写这个,在 main 方法中,没有'create = true', 使用 Prepared Statement 但似乎没有任何效果。
提前致谢!!!
【问题讨论】: