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
asked Mar 6, 2010 at 9:37
Anand
10.4k26 gold badges92 silver badges139 bronze badges
-
1Note 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.BalusC– BalusC2010年03月06日 11:58:32 +00:00Commented Mar 6, 2010 at 11:58
2 Answers 2
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
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);
LPL
17.1k6 gold badges55 silver badges98 bronze badges
1 Comment
BalusC
Uhm, I think you didn't understood the question nor the already accepted answer :)
default