java tira error al haber consulta de bd mysql
Publicado por Cristian (1 intervención) el 17/12/2019 16:01:24
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
btnBuscar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//con getModel() me permite ingresar o escribir elementos de la consulta en la tabla. hay un video de esomodelo = (DefaultTableModel) tblVehiculos.getModel(); //hay un curso youtube que explica esta linea del mismo tipo
//DefaultTableModel modelo = (DefaultTableModel) tblVehiculos.getModel(); //hay un curso youtube que explica esta linea del mismo tipomodelo.setRowCount(0);
if (cbAuto.isSelected()){
if(cbMoto.isSelected()){
tipoVehiculo = "";
}else
{ tipoVehiculo = "Automovil";
} }else if(cbMoto.isSelected()){
tipoVehiculo = "Motocicleta";
}if(rbFueraParq.isSelected()){
estado = "No disponible";
}if(rbEnParq.isSelected()){
estado = "Disponible";
}if (dcFechaBusqueda.getDatoFecha()!=null){ //pregunta si la fecha no ta vacia
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = (Date) dcFechaBusqueda.getDatoFecha();
fecha = dateFormat.format(date);
} try {Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/bdparqueadero","root","");
java.sql.Statement stat = con.createStatement();
consulta = "SELECT * FROM vehiculos WHERE estado='" + estado + "'AND tipovehiculo LIKE'%" + tipoVehiculo + "%' AND placa LIKE '%" + tfPlaca.getText() + "%' AND propietario LIKE '%" +tfPropietario.getText() + "%' AND horaentrada LIKE '" + fecha + "%'";
System.out.println(consulta);
ResultSet rs = stat.executeQuery(consulta);
rs.first();//apunta el puntero a la primer posición del ResulSet
//if(rs.next() ){if( (tfPlaca.getText().equals("") && tfPropietario.getText().equals("")) || (!cbMoto.isSelected() && !cbAuto .isSelected()) ){
if(tfPlaca.getText().equals("") && tfPropietario.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Ingresar patente o conductor");
}if(!cbMoto.isSelected() && !cbAuto .isSelected()){
JOptionPane.showMessageDialog(null, "seleccione moto y/o vehículo");
} } else { do {String horasalida = rs.getString(6);
String pago = rs.getString(7);
if(horasalida == null){
horasalida = "no ha salido";
pago = "0";
} else { //arranca en posic 10 y termina en pos 16horasalida = rs.getString(6).substring(10).substring(0,6);
pago = rs.getString(7);
}String[] fila = {rs.getString(1),rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5).substring(10).substring(0,6), horasalida, "$" + pago};
/*if(rs.getBoolean(null)){ JOptionPane.showMessageDialog(null, "NO SE ENCONTRARON COINCIDENCIAS"); } else {*/modelo.addRow(fila);
System.out.println(rs.getString(7));
//} //med arregla el elemento a la tabla //System.out.println(rs.getString(2));}while(rs.next()); //mientras haya algo en rs
}} catch (ClassNotFoundException e) {
// TODO Auto-generated catch blocke.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch blocke.printStackTrace();
} }});
tengo una interfaz donde registro motos o autos estacionados. hasta ahora no registre ninguna moto. y cuando quiero consultar las motos registradas me tira ese error de arriba. como capturo el error? probe con if por todos lados, pero nada


Valora esta pregunta


0

