| |||
![]() Buenas!!! intento hacer una simple consulta en el mysql todo perfecto pero cuando lo realizo desde el jbuilder no me coje el valor siempre me devuelve 0 y no debería ser así;alguien me puede ayudar por favor, muchas gracias..ahí os dejo el codigo: //este es el error q salta java.sql.SQLException: Column 'cod' not found. //subprograma: //obtener el cod materia dado un codGrupo public int obtCodMateria(String pCodGrupo,Connection pCon) throws SQLException { int codMateria = 0; String sql="SELECT codMateria FROM grupo WHERE cod='"+pCodGrupo+"';"; Statement stmt = pCon.createStatement(); ResultSet rs = stmt.executeQuery(sql); boolean enc=false; try { while (!enc && rs.next()) { String codigo = rs.getString("cod"); codMateria = rs.getInt("codMateria"); if (codigo.compareTo(pCodGrupo) == 0) { enc = true; } } } catch (SQLException ex) { System.out.println(ex); } return codMateria; } |
| |||
Respuesta: Consulta SqlExceptio column not found Más facil de lo q pensaba //obtener el cod materia dado un codGrupo public int obtCodMateria(String pCodGrupo,Connection pCon) throws SQLException { int codMateria = 0; String sql="SELECT codMateria FROM grupo WHERE cod='"+pCodGrupo+"';"; Statement stmt = pCon.createStatement(); ResultSet rs = stmt.executeQuery(sql); while ( rs.next()) { codMateria = rs.getInt("codMateria"); } return codMateria; } |