2 messages in com.mysql.lists.javaRe: Can you create a new database thr...
FromSent OnAttachments
Mufaddal12 Feb 2003 00:54 
Mark Matthews12 Feb 2003 13:38 
Subject:Re: Can you create a new database thru JDBC using the mysql driver ?
From:Mark Matthews (ma@mysql.com)
Date:02/12/2003 01:38:52 PM
List:com.mysql.lists.java

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

Mufaddal wrote:

Hi ,

Can we connect a new database using the mysql driver. ?

Like when we do this thru the java code:

Class.forName("com.mysql.jdbc.Driver"); ConnectionPool cp = DriverManager.getConnection("jdbc:mysql://localhost/cwdb?user=root");

can we specify some kind of flag like createDB = true ?

ConnectionPool cp = DriverManager.getConnection("jdbc:mysql://localhost/ cwdb?user=root,createDB=true");

No, and there probably will never be, mostly because it's outside the scope of what a JDBC driver should be doing.

However, you don't have to specify a database on connection, so you could use a JDBC URL like:

jdbc:mysql://localhost/?user=root

And then issue a query:

SHOW DATABASES LIKE 'cwdb'

and if the result set is empty, issue:

CREATE DATABASE cwdb

-Mark

- -- MySQL 2003 Users Conference -> http://www.mysql.com/events/uc2003/

For technical support contracts, visit https://order.mysql.com/?ref=mmma

iD8DBQE+Sr8FtvXNTca6JD8RAjwNAJ9655thflma/g4Y+h523d75icFmUQCgpuny 3+q1eIec5H2mrx6mnZSdH60= =TIRD -----END PGP SIGNATURE-----