MySQL Forums :: Connector/JDBC and Java :: CREATE DATABASE

Advanced Search

Posted by: Peter Toye ()
Date: July 12, 2006 02:14PM

y0015559 Wrote:
> Hi all!
> Can anybody tell me, how can I create a database
> using JDBC?
> Main problem, I don't know how I can create a
> connection if a database don’t exist.
> For example
> Class.forName("com.mysql.jdbc.Driver").newInstance
> ();
> con =
> DriverManager.getConnection("jdbc:mysql:///test",
> "root", "secret");
> How can I create a connection, if the database
> "test" don’t yet exist and I want create it?
> Many Thanks

You don't need to specify a database - the documentation is a bit confusing here.

Conn = DriverManager.getConnection

works OK.

Then create a statement and execute the CREATE statement


int Result=s.executeUpdate("CREATE DATABASE databasename");


Options: ReplyQuote

Subject Written By Posted
CREATE DATABASE y0015559 06/28/2006 12:10PM
Re: CREATE DATABASE Mary Nkwana 07/06/2006 12:16AM
Re: CREATE DATABASE Peter Toye 07/12/2006 02:14PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.