crear una base de datos mysql con nombre de usuario y contraseña del código java

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
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'


can i do that on java code ?

preguntado el 28 de agosto de 12 a las 15:08

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. -

@Polppan a procedure ?? if i export my database do i have this procedure ?? -

It is certainly possible from Java.. You may need to do with seperate statements if you are not using database stored procedures. -

@Polppan how i create procedure on a file and call it on java ? -

Some examples on creating database from Java Una Dos Tres -

2 Respuestas

There is a example Create database using java

Espero que esto ayude

Respondido 28 ago 12, 16:08

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 or haz tu propia pregunta.