CREATE DATABASE query using java jdbc and prepared statement returns syntax error

匆匆过客 提交于 2019-12-01 09:27:59

You cannot have the database name as a bind variable -- you have to embed it in the query literal. Change your query into this instead:

String query = "CREATE DATABASE " + getDatabaseName();

You can also use a plain Statement (instead of PreparedStatement) for running this SQL.

M Sach
Conn = DriverManager.getConnection 
("jdbc:mysql://localhost/?user=root&password=rootpassword"); 
Statement s=Conn.createStatement(); 

int Result=s.executeUpdate("CREATE DATABASE databasename");

see

http://forums.mysql.com/read.php?39,99321,102211#msg-102211

Create MySQL database from Java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!