Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/vehiculos", "root", "");
- Statement s = conexion.createStatement();
- if (!marcas.equals("Todos") && emisiones.equals("Todos")) {
- ResultSet rs = s.executeQuery("select *from vehiculos where marca ='" + marcas.getSelectedItem() + "';");
- DefaultTableModel modelo = new DefaultTableModel();
- ResultSetMetaData rsMd = rs.getMetaData();
- int cantidadColumnas = rsMd.getColumnCount();
- for (int i = 1; i <= cantidadColumnas; i++) modelo.addColumn(rsMd.getColumnLabel(i));
- while (rs.next()) {
- Object[] fila = new Object[cantidadColumnas];
- for (int i = 0; i < cantidadColumnas; i++) fila[i] = rs.getObject(i + 1);
- modelo.addRow(fila);
- rs.close();
- jtQuery.setModel(modelo);
- }
- }else if(marcas.equals("Todos") && !emisiones.equals("Todos")){
- ResultSet rs = s.executeQuery("select *from vehiculos where emisiones " + emisiones.getSelectedItem() + ";");
- DefaultTableModel modelo = new DefaultTableModel();
- ResultSetMetaData rsMd = rs.getMetaData();
- int cantidadColumnas = rsMd.getColumnCount();
- for (int i = 1; i <= cantidadColumnas; i++) modelo.addColumn(rsMd.getColumnLabel(i));
- while (rs.next()) {
- Object[] fila = new Object[cantidadColumnas];
- for (int i = 0; i < cantidadColumnas; i++) fila[i] = rs.getObject(i + 1);
- modelo.addRow(fila);
- rs.close();
- jtQuery.setModel(modelo);
- }
- }else if (!marcas.equals("Todos") && !emisiones.equals("Todos")) {
- ResultSet rs = s.executeQuery("select *from vehiculos where marca ='" + marcas.getSelectedItem() + "and emisiones " + emisiones.getSelectedItem() + "';");
- DefaultTableModel modelo = new DefaultTableModel();
- ResultSetMetaData rsMd = rs.getMetaData();
- int cantidadColumnas = rsMd.getColumnCount();
- for (int i = 1; i <= cantidadColumnas; i++) modelo.addColumn(rsMd.getColumnLabel(i));
- while (rs.next()) {
- Object[] fila = new Object[cantidadColumnas];
- for (int i = 0; i < cantidadColumnas; i++) fila[i] = rs.getObject(i + 1);
- modelo.addRow(fila);
- rs.close();
- jtQuery.setModel(modelo);
- }
- }
- conexion.close();
- } catch (Exception ex) {ex.printStackTrace();}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement