AYUDA CON EL OBJETO PrepardStatement
Publicado por ashleycole (2 intervenciones) el 09/11/2013 07:04:04
Hola a todos,,,saben mi problema ace poco espese a trabajar con el objeto PrepardStatement , yo programo en 3 capas,,mi codigo es el siguiente.
--AGREGAR
--ELIMINAR
--LISTADO (PARA MOSTRAR LOS DATOS EN LA TABLA)
MI PROBLEMA ES CON "CONSULTAR" ,no se me ocurre como hacer..ME DARIAN ALGUNA IDEA XFA...........SALU2 Y GRACIAS DE ANTEMANO
PD:uso netbeans y sql
--AGREGAR
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public boolean agregar(Producto p){
sql = "insert into productos1 values(?,?,?,?)";
try {
ps = cn.prepareStatement(sql);
ps.setString(1, p.getCodprod());
ps.setString(2, p.getDescrip());
ps.setInt(3, p.getCantidad());
ps.setDouble(4, p.getPreciou());
int resu = ps.executeUpdate();
if(resu==1)
return true;
else
return false;
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, e1.getMessage());
return false;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public boolean eliminar(String cod){
sql="delete from productos1 WHERE codpro=?";
try {
ps=cn.prepareStatement(sql);
ps.setString(1,cod);
int resu=ps.executeUpdate();
if(resu==1)
return true;
else
return false;
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, e1.getMessage());
return false;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public void listado(JTable tbl){
sql = "select * from.productos1";
DefaultTableModel m1 = (DefaultTableModel)tbl.getModel();
try {
m1.setRowCount(0);
ps = cn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
Object[]fila={rs.getString(1) , rs.getString(2) , rs.getInt(3) , rs.getDouble(4)};
m1.addRow(fila);
}
} catch (SQLException e1) {
}
}
}
MI PROBLEMA ES CON "CONSULTAR" ,no se me ocurre como hacer..ME DARIAN ALGUNA IDEA XFA...........SALU2 Y GRACIAS DE ANTEMANO
PD:uso netbeans y sql
Valora esta pregunta


0