consulta si tabla sql esta vacía
Publicado por Alejandro (21 intervenciones) el 03/09/2019 16:34:25
Necesito saber si la tabla de la base de datos esta vacía o no..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public void Cargarnum(){
PreparedStatement pst = null;
ResultSet rs = null;
ResultSet rst = null;
String num = "1";
String ncomp = "";
int entero;
int total;
String total2 = "";
try{
String sql = "SELECT count(*) FROM ventas_clientes";
pst =connect().prepareStatement(sql);
rst = pst.executeQuery();
}catch(Exception e){
System.err.println("Error" + e);
}
if(rst == null){
lblncomp.setText(num);
}else{
try{
String sql = "SELECT ncomp FROM ventas_clientes";
pst =connect().prepareStatement(sql);
rs = pst.executeQuery();
while(rs.next()){
ncomp = rs.getString("ncomp");
entero = Integer.parseInt(ncomp);
total = entero +1;
total2 = Integer.toString(total);
}
lblncomp.setText(total2);
}catch(Exception e){
System.err.println("Error" + e);
}
}
}
Valora esta pregunta


0