Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void asignarCodigo() throws ClassNotFoundException, SQLException {
- //Cargo driver
- Class.forName("com.mysql.jdbc.Driver");
- //Creo conexión
- Connection cnx = DriverManager.getConnection(ruta, usuario, pass);
- //Creo sentencia
- Statement sentencia = cnx.createStatement();
- //Ejecuto sentencia sobre un resultset
- ResultSet resultado = sentencia.executeQuery("SELECT * FROM tabla;");
- //Variable para saber e ltamaño de ResultSet
- int ultimo = 0;
- //Recorro el bucle para saber el último código de departamento
- while (resultado.next()) {
- ultimo = resultado.getInt(1);
- }
- // Sumo uno al último código de departamento
- ultimo++;
- //Asigno el nuevo id al campo de texto
- jTextFieldCodigo.setText(String.valueOf(ultimo));
- //Libero recursos
- ////resultado.close();
- sentencia.close();
- cnx.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement