从Java创建MySQL数据库

是否可以从Java创建MySQL数据库?

我只看过这样的连接URL示例,其中在URL中指定了数据库名称:

String url="jdbc:mysql://localhost:3306/test";

Connection con = DriverManager.getConnection( url, "cb0", "xxx" );

当我只有登录名和密码时,如何创建MySQL数据库?

回答:

jdbc连接中不需要数据库,因此您可以执行以下建议的操作:http://forums.mysql.com/read.php?39,99321,102211#msg-102211和http://marc.info

/?l = mysql-java&m = 104508605511590&w = 2:

Conn = DriverManager.getConnection

("jdbc:mysql://localhost/?user=root&password=rootpassword");

s=Conn.createStatement();

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

以上是 从Java创建MySQL数据库 的全部内容, 来源链接: utcz.com/qa/407492.html

回到顶部