Código:
no se por que me da un error://Imprimo Filas de la tabla Integer idUser = rs.getInt("idUser"); String first = rs.getString("FirstName"); String last = rs.getString("LastName"); System.out.println(idUser + " se llama: " + first + " " + last);
Código:
Exception in thread "main" java.sql.SQLException: Estado del cursor no válido: sin fila actual. at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source) at org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedResultSet.checkOnRow(Unknown Source) at org.apache.derby.impl.jdbc.EmbedResultSet.getColumn(Unknown Source) at org.apache.derby.impl.jdbc.EmbedResultSet.getInt(Unknown Source) at org.apache.derby.impl.jdbc.EmbedResultSet.getInt(Unknown Source) at db_embebida.CrearBaseDeDatos.main(CrearBaseDeDatos.java:56) Caused by: ERROR 24000: Estado del cursor no válido: sin fila actual. at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source) ... 11 more Java Result: 1
Código:
public static void main(String[] args) throws SQLException { //Establezco la conexion con la base de datos, si no existe la crea String db="prueba33"; Connection conn = DriverManager.getConnection("jdbc:derby:"+db+";create=true"); System.out.println("DB "+db+" creada"); //creo una tabla con 3 columnas Statement st = conn.createStatement(); String sqlCreateTableUsers = "CREATE TABLE users ( " + "FirstName VARCHAR(20) NOT NULL, " + "LastName VARCHAR(20) NOT NULL, " + "idUser INTEGER NOT NULL CONSTRAINT idUser_PK PRIMARY KEY " + ")"; st.execute(sqlCreateTableUsers); System.out.println("Tablas creadas"); //Inserto Datos en la tabla creada st.execute("INSERT INTO users VALUES('jose','casta',1)"); st.execute("INSERT INTO users VALUES('del','belt',2)"); st.execute("INSERT INTO users VALUES('jos','vel',3)"); System.out.println("Datos Ingresados"); //Consulto los datos ingresados //resultSet.. ResultSet rs=st.executeQuery("SELECT * FROM users"); //Contar filas int nOfRows=0; while(rs.next()){ nOfRows++; } System.out.println("filas: "+nOfRows); //Imprimo Filas de la tabla Integer idUser = rs.getInt("idUser"); String first = rs.getString("FirstName"); String last = rs.getString("LastName"); System.out.println(idUser + " se llama: " + first + " " + last); conn.close(); }
Alguien sabe que tengo mal que no me imprime la consulta? gracias