Re: CREATE DATABASE
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
Subject
Written By
Posted
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.