How to Create a MySql Database using JDBC
Can we create a new MySQL database( not a table, I want a new database) from java code ? I have searched the internet and I get code only for connecting with existing mysql databases. Can i create a new database at run time using java code.
plea开发者_StackOverflow中文版se help
In your connection string omit a database name and then execute Create database command.
Connection String: jdbc:mysql://localhost
Create Database Syntax : stm.executeUpdate("CREATE DATABASE dbname")
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1";
Connection conn = DriverManager.getConnection(url);
精彩评论