Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class MigracionBaseDatos {
- // Driver JDBC y URL base de datos
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
- static final String DB_URL = "";
- // Credenciales base datos
- static final String USER = "";
- static final String PASS = "";
- // Crear las tablas MIGRACION_EXPEDIENTE Y MIGRACION_DOCUMENTO si no estuviesen creadas ya en la base de datos
- private void crearTablas() {
- String migracionExpediente = "CREATE TABLE MIGRACION_EXPEDIENTE ("
- + "SID INT(64) NOT NULL AUTO_INCREMENT,"
- + "SID_EXPEDIENTE INT(64) NOT NULL,"
- + "FECHA_ULTIMA_ACTUALIZACION TIMESTAMP(6),"
- + "RESULTADO VARCHAR(2),"
- + "SID_GEDE VARCHAR(2),"
- + "ERROR INT(64))";
- try {
- Class.forName(jdbcDriver);
- con = DriverManager.getConnection(dbAddress + dbName, userName, password);
- statement = con.createStatement();
- //The next line has the issue
- statement.executeUpdate(myTableName);
- System.out.println("Table Created");
- }
- catch (SQLException e ) {
- System.out.println("An error has occurred on Table Creation");
- }
- catch (ClassNotFoundException e) {
- System.out.println("An Mysql drivers were not found");
- }
- }
- public static void main(String[] args) {
- Connection conn = null;
- Statement stmt = null;
- try{
- // Registrar driver JSBC
- Class.forName("com.mysql.jdbc.Driver");
- //STEP 3: Open a connection
- System.out.println("Connecting to a selected database...");
- conn = DriverManager.getConnection(DB_URL, USER, PASS);
- System.out.println("Connected database successfully...");
- //STEP 4: Execute a query
- System.out.println("Creating table in given database...");
- stmt = conn.createStatement();
- String sql = "CREATE TABLE REGISTRATION " +
- "(id INTEGER not NULL, " +
- " first VARCHAR(255), " +
- " last VARCHAR(255), " +
- " age INTEGER, " +
- " PRIMARY KEY ( id ))";
- stmt.executeUpdate(sql);
- System.out.println("Created table in given database...");
- }catch(SQLException se){
- //Handle errors for JDBC
- se.printStackTrace();
- }catch(Exception e){
- //Handle errors for Class.forName
- e.printStackTrace();
- }finally{
- //finally block used to close resources
- try{
- if(stmt!=null)
- conn.close();
- }catch(SQLException se){
- }// do nothing
- try{
- if(conn!=null)
- conn.close();
- }catch(SQLException se){
- se.printStackTrace();
- }//end finally try
- }//end try
- System.out.println("Goodbye!");
- }//end main
- }//end JDBCExample
Add Comment
Please, Sign In to add comment