Foros del Web » Programación para mayores de 30 ;) » Java »

J2EE-->crear 2 tablas en el mismo archivo .java

Estas en el tema de J2EE-->crear 2 tablas en el mismo archivo .java en el foro de Java en Foros del Web. Hola muchachos necesito saber como creo en el mismo archivo 2 tablas diferentes gracias si me pueden ayudar se lo agradeceria mucho.Las tablas son locate ...
  #1 (permalink)  
Antiguo 24/11/2009, 16:56
Avatar de diegofernando  
Fecha de Ingreso: marzo-2009
Mensajes: 71
Antigüedad: 15 años, 2 meses
Puntos: 0
J2EE-->crear 2 tablas en el mismo archivo .java

Hola muchachos necesito saber como creo en el mismo archivo 2 tablas diferentes
gracias si me pueden ayudar se lo agradeceria mucho.Las tablas son locate y cd.
Esto es lo que tengo:


import java.sql.*;
public class MyOwnJDBCProgram {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String url = "jdbc:derby://localhost:1527/sample";
Connection con;
String createString;
createString = "create table location " +
"(Location_id, Integer not NULL PRIMARY KEY, " +
"Location VARCHAR(40))";
Statement stmt;
try {
// Load database driver. This is old method of loading
// database driver.
Class.forName("org.apache.derby.jdbc.ClientDriver" );

} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}

try {
// Create database connection
con = DriverManager.getConnection(url,
"app", "app");

// Create a statement and execute it
stmt = con.createStatement();
stmt.executeUpdate(createString);

// If there is no exception, the COFFEES table must be successfully created
System.out.println("location table is successfully created");

stmt.close();
con.close();

} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}

/** Connection con1;
String createString1;
createString1 = "create table cd " +
"(cd_id, integer not null primary key, +
"title varchar(40),
"author varchar(40),
"year_created integer,
"location integer,
"rating integer,
//CONSTRAINT FK_CD_LOCATION FOREIGN KEY (LOCATION) REFERENCES LOCATION(LOCATION_ID))";



Statement stmt1;
try {
// Load database driver. This is old method of loading
// database driver.
Class.forName("org.apache.derby.jdbc.ClientDriver" );

} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}

try {
// Create database connection
con1 = DriverManager.getConnection(url,
"app", "app");

// Create a statement and execute it
stmt1 = con1.createStatement();
stmt1.executeUpdate(createString1);

// If there is no exception, the COFFEES table must be successfully created
System.out.println("cd table is successfully created");

// Close statement and connection
stmt1.close();
con1.close();

} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}


//createString1= "create table cd " +
//"(cd_id, integer not null primary key, +
//"title varchar(40),
//"author varchar(40),
//"year_created integer,
//"location integer,
//"rating integer,
//CONSTRAINT FK_CD_LOCATION FOREIGN KEY (LOCATION) REFERENCES LOCATION(LOCATION_ID))";

*/
}

}
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:06.