我有这个:
public static void createTemporaryTable() {
Statement s = null;
sentence = "CREATE TEMPORARY TABLE Book (ISBN int NOT NULL, " +
"title varchar(45), author varchar(45), price double, PRIMARY KEY (`ISBN`));";
try {
s = Conexion.getInstancia().createStatement();
s.executeUpdate(sentence);
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
s.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
然后:
public class System {
public static void main(String[] args) {
SqlSentencesList.createTemporaryTable();
}
}
但是当我执行时select * from Book
,MySQL 告诉我Book
表不存在。我没有从 java 收到任何错误消息,所以应该创建表,但事实并非如此。
如果我直接在 mysql 中执行相同的 sql 语句来创建临时表,它就可以正常工作。
这是我的Conexion
课:
public class Conexion {
private static Connection conexion = null;
private Conexion() {
}
public static Connection getInstancia() {
if (conexion == null) {
try {
Class.forName("com.mysql.jdbc.Driver");
conexion = DriverManager.getConnection(
"jdbc:mysql://localhost/Esquema_VentaLibros","gustavo", "123581321");
} catch (SQLException sqlex) {
sqlex.printStackTrace();
} catch(ClassNotFoundException cnfex) {
cnfex.printStackTrace();
}
return conexion;
}
else {
return conexion;
}
}
}