从Java创建MySQL数据库 [英] Create MySQL database from Java
问题描述
是否有可能从Java中创建MySQL中的数据库?
Is there any possibility of creating a database within MySQL from Java?
我只知道
String url="jdbc:mysql://localhost:3306/test";
Connection con = DriverManager.getConnection( url, "cb0", "xxx" );
语法,但这里必须在'url'中指定数据库名称。
syntax, but here you have to specify a database name in the 'url'.
当我只有一个登录名和密码,但不知道现有的数据库时,如何创建一个MySQL数据库?
How can I create a MySQL database when I only have a login name and password, but no knowledge about the existing databases?
推荐答案
在jdbc连接中不需要数据库,因此您可以执行 http://forums.mysql.com/read.php?39,99321,102211#msg-102211 和 http://marc.info/?l=mysql-java&m=104508605511590&w=2 :
The database isn't required in the jdbc connection, so you can do something like recommended at http://forums.mysql.com/read.php?39,99321,102211#msg-102211 and 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数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!