Buenas a todos comunidad, ¿que tal va todo?, me pasaba por aquí porque estoy teniendo unos problemas de conexión entre java y una base de datos embedida, estoy usando como puente derby, y a la hora de crear la tabla e insertar datos no tengo ningun problema, la cosa esta en cuando intento recuperar esos datos. Cuando intento llamarlos me dice que el estado del cursor no es valido que esta sin fila actual.
Haber si alguien consigue ver en que estoy fallando, soy bastante nuevo en java y no tengo mucha idea por eso no se por donde cogerlo. Os dejo los codigos que he usado.
Creación de Tablas y Datos
Consulta a base de datos
Error que me tira
Muchas gracias de antemano a todos por prestarme atención.
Haber si alguien consigue ver en que estoy fallando, soy bastante nuevo en java y no tengo mucha idea por eso no se por donde cogerlo. Os dejo los codigos que he usado.
Creación de Tablas y Datos
Código [Seleccionar]
public class Derby {
public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
public static final String JDBC_URL = "jdbc:derby:zadb;create=true";
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName(DRIVER);
Connection connection = DriverManager.getConnection(JDBC_URL);
connection.createStatement().execute("create table channels(channel varchar(20),topic varchar(20), videoclip varchar(20))");
connection.createStatement().execute("insert into channels values "
+ "('oodp', 'creational', 'singleton'),"
+ "('oodp', 'creational', 'factory method'),"
+ "('oodp', 'creational', 'abstract factory')");
System.out.println("Channels table created and records successfully inserted...");
}
}
Consulta a base de datos
Código [Seleccionar]
public class QueryDB {
public static final String SQL_STATEMENT = "select * from channels";
public static void main(String[] args) throws SQLException {
Connection connection = DriverManager.getConnection(Derby.JDBC_URL);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SQL_STATEMENT);
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int columnCount = resultSetMetaData.getColumnCount();
for (int x = 1; x <= columnCount; x++) System.out.format("%20s", resultSet.getString(x) + " | ");
while (resultSet.next()){
System.out.println("");
for (int x = 1; x <= columnCount;x++) System.out.format("%20s", resultSet.getString(x) + " | ");
}
if (statement != null) statement.close();
if (connection != null) connection.close();
}
}
Error que me tira
Código [Seleccionar]
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.getColumnType(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)
at derby.QueryDB.main(QueryDB.java:19)
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)
... 10 more
Java Result: 1
Muchas gracias de antemano a todos por prestarme atención.
