Re: CREATE DATABASE
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
("jdbc:mysql://localhost/?user=root&password=rootpassword");

works OK.

Then create a statement and execute the CREATE statement

s=Conn.createStatement();

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

Peter

Options: ReplyQuote


Subject
Written By
Posted
June 28, 2006 12:10PM
July 06, 2006 12:16AM
Re: CREATE DATABASE
July 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.