crear una base de datos mysql con nombre de usuario y contraseña del código java
Frecuentes
Visto 4,891 veces
2
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 ?
2 Respuestas
0
There is a example Create database using java
Espero que esto ayude
Respondido 28 ago 12, 16:08
0
seeing your comment about running script from a file, you can check my answer in the following post:
Java/Mysql ¿Cómo inyectaría un archivo SQL completo en un servidor mysql?
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.
contestado el 23 de mayo de 17 a las 13:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas java mysql database jdbc or haz tu propia pregunta.
Why don't you create a database stored procedure which does all your database creation, tables etc and call this procedure from Java by passing necessary parameters. - Jacob
@Polppan a procedure ?? if i export my database do i have this procedure ?? - Adel Bachene
It is certainly possible from Java.. You may need to do with seperate statements if you are not using database stored procedures. - Jacob
@Polppan how i create procedure on a file and call it on java ? - Adel Bachene
Some examples on creating database from Java Una Dos Tres - Jacob