Could you help with this problem.
I\'m trying to create and then use a database called TIGER.
I have no problem if I create the database in MySQL and it runs
Few points to note and correct-
private Connection con;
but you are using it as statement = Conn.createStatement();
You have declared a reference to Prepared Statement private PreparedStatement statement;
but you are creating instance of Statement statement = Conn.createStatement();
.
Your code should be -
try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/?user=root&password=rootpassword");
Statement statement = con.createStatement();
int myResult = statement.executeUpdate("CREATE DATABASE IF NOT EXISTS TIGER"); //should get 0
}
catch (SQLException e) {
System.out.println("Database creation failed");
e.printStackTrace();
}
Note that when the return value for executeUpdate is 0, it can mean one of two things:
The statement executed was an update statement that affected zero rows.
The statement executed was a DDL statement.
Documentation