gpt4 book ai didi

java - 从 Java 创建 MySQL 数据库

转载 作者:IT老高 更新时间:2023-10-28 21:22:03 25 4
gpt4 key购买 nike

是否可以从 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 - 从 Java 创建 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/717436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com