所以我正在学习 JBDC,我正在尝试通过 java 创建一个表。我已经测试了用户'calgar',它可以通过mysql命令创建一个表,但是当我尝试通过java实现它时它没有影响。没有创建表,但也没有错误或异常。有人有什么建议吗?
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
try{
System.out.println("Connecting to driver/database..");
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/firstdatabase","calgar","password");
System.out.println("Connection successful");
statement = connection.createStatement();
statement.execute("CREATE TABLE books(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100),author VARCHAR(100),publisher VARCHAR(100))");
}
catch(ClassNotFoundException error){
System.out.println("Class Not Found Error " + error.getMessage());
}
catch(SQLException error){
System.out.println("SQL Error " + error.getMessage());
}
finally
{
if(connection != null)
try{connection.close();}
catch(SQLException ignore){}
if(statement != null)
try{statement.close();}
catch(SQLException ignore){}
}