Reputation: 994
How to create mysql database with username and password from java code ? and create all the tables ?
i was googling and i found this code
Conn = DriverManager.getConnection
("jdbc:mysql://localhost/?user=root&password=rootpassword");
s=Conn.createStatement();
int Result=s.executeUpdate("CREATE DATABASE databasename");
but in my case i need to :
-set a username and password from java
make sure that:
MySQL charset: UTF-8 Unicode (utf8)
MySQL connection collation: utf8_general_ci
my database and table collations are set to: utf8_general_ci or utf8_unicode_ci
and after that i must execute this in mysql : SET NAMES 'utf8'
SET CHARACTER SET utf8
can i do that on java code ?
Upvotes: 2
Views: 5088
Reputation:
seeing your comment about running script from a file, you can check my answer in the following post:
Java/Mysql How would you inject an entire SQL file to a mysql server?
it will allow you to run a file through shell. It was made for linux but you can easily rename the function and the command to run under windows. this will allow you to run all the commands from a file. so actually you can have an export of some database and run it every time you need to create a similar database, with the support of username and password too.
Upvotes: 0
Reputation: 1184
There is a example Create database using java
Hope this helps
Upvotes: 0