tags:

views:

50

answers:

2

Hi,

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

+1  A: 

In your connection string omit a database name. i.e. jdbc:mysql://localhost and then execute stm.executeUdate("CREATE DATABASE dbname")

Bozho
A: 

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

Uhm, I think you didn't understood the question nor the already accepted answer :)
BalusC