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
- create all the tables
Asegúrate de eso:
Juego de caracteres MySQL: UTF-8 Unicode (utf8)
Intercalación de conexión MySQL: 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'
CONFIGURAR JUEGO DE CARACTERES utf8
can i do that on java code ?
preguntado el 28 de agosto de 12 a las 15:08
seeing your comment about running script from a file, you can check my answer in the following post:
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.