Anand
Anand

Reputation: 10400

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.

please help

Upvotes: 0

Views: 4096

Answers (2)

Bozho
Bozho

Reputation: 597402

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")

Upvotes: 6

user287728
user287728

Reputation: 1

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);

Upvotes: -1

Related Questions