【发布时间】:2020-12-15 13:25:17
【问题描述】:
我想用这种方法创建一个新的 mySQL 表。 数据库连接工作正常。 我做了很多这样的工作声明,但是这个,创建一个表是行不通的。 所以错误必须在这几行代码中。 在底部我添加了错误消息。
public void createNewTable(){
DatabaseConnection connectNow = new DatabaseConnection();
Connection connectDb = connectNow.getConnection();
String tableName = "users";
try {
String createTable = "CREATE TABLE ? (firstname varchar(30), lastname varchar(30), tel integer" +
"email varchar(40), arrive_stamp timestamp, quit_stamp timestamp)";
PreparedStatement myStmt = connectDb.prepareStatement(createTable);
myStmt.setString(1, tableName);
myStmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
e.getCause();
}
}
Illegal operation on empty result set.
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near ''users' (firstname varchar(30),
lastname varchar(30), tel integer, email varchar' at line 1
【问题讨论】: