0

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
  • 1
    Note that not all JDBC drivers supports all DDL statements and that it's generally considered bad practice to create db's and tables using JDBC, unless you'd like to (re)invent a DB manager tool in Java. For normal apps creating the datamodel ought to be a separate task. Commented Mar 6, 2010 at 11:58

2 Answers 2

6

In your connection string omit a database name and then execute Create database command.

Connection String: jdbc:mysql://localhost

Create Database Syntax : stm.executeUpdate("CREATE DATABASE dbname")

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.