dbo
Publicado por Juan (1 intervención) el 17/05/2006 15:17:37
private void openBD() {
try {
Conexion conx = new Conexion();
con = conx.obtenerConexion();
} catch (Throwable e) {
e.printStackTrace();
}
}
private void closeExecuteUpdate() {
try {
stmt.close();
con.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
private void closeExecuteQuery() {
try {
result.close();
stmt.close();
con.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
Connection con = null;
PreparedStatement stmt = null;
ResultSet result = null;
public Collection searchAll(Sistema si);
public Sistema searchSistema(String id);
public void update(Sistema si);
public void create(Sistema si);
Collection sistemas = new ArrayList();
try {
String query = "SELECT * FROM usuario WHERE nombre LIKE '%"
+ si.getNombre() + "%'";
this.openBD();
stmt = con.prepareStatement(query);
result = stmt.executeQuery();
while (result.next()) {
System.out.println("Datos Obtenidos:... [ok]");
String user = result.getString("user");
String pass = result.getString("pass");
String nombre = result.getString("nombre");
Integer edad = new Integer(result.getString("edad"));
sistemas.add(new Sistema(edad, nombre, pass, user));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
closeExecuteQuery();
}
return sistemas;
try {
Conexion conx = new Conexion();
con = conx.obtenerConexion();
} catch (Throwable e) {
e.printStackTrace();
}
}
private void closeExecuteUpdate() {
try {
stmt.close();
con.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
private void closeExecuteQuery() {
try {
result.close();
stmt.close();
con.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
Connection con = null;
PreparedStatement stmt = null;
ResultSet result = null;
public Collection searchAll(Sistema si);
public Sistema searchSistema(String id);
public void update(Sistema si);
public void create(Sistema si);
Collection sistemas = new ArrayList();
try {
String query = "SELECT * FROM usuario WHERE nombre LIKE '%"
+ si.getNombre() + "%'";
this.openBD();
stmt = con.prepareStatement(query);
result = stmt.executeQuery();
while (result.next()) {
System.out.println("Datos Obtenidos:... [ok]");
String user = result.getString("user");
String pass = result.getString("pass");
String nombre = result.getString("nombre");
Integer edad = new Integer(result.getString("edad"));
sistemas.add(new Sistema(edad, nombre, pass, user));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
closeExecuteQuery();
}
return sistemas;
Valora esta pregunta


0