I am using CachedRowSetImpl , I can get data from Database , BUT I can not insert .
this is the Code :
public class NewClass {
static final String DATABASE_URL = "jdbc:derby://localhost:1527/TaskDB;create=true";
static final String USERNAME = "user";
static final String PASSWORD = "user";
public static void main (String [] agr) throws SQLException
{
CachedRowSetImpl rs = new CachedRowSetImpl();
rs.setUrl(DATABASE_URL);
rs.setUsername(USERNAME);
rs.setPassword(PASSWORD);
rs.setCommand("SELECT * FROM TASKTABLE");
rs.execute();
rs.moveToInsertRow();
rs.updateString("Column_Name","DataString");
rs.insertRow();
rs.moveToCurrentRow();
rs.updateRow();
}
}
it throw the Exception :
Exception in thread "main" java.sql.SQLException: Failed on insert row at com.sun.rowset.CachedRowSetImpl.insertRow(CachedRowSetImpl.java:5462) at NewClass.main(NewClass.java:32)
I have tried JdbcRowSetImpl Instead of CachedRowSetImpl , and it's work fine
UPDATE : I used this code to catch more Details about the Exceptions :
catch(SQLException e) {
do {
System.out.println("SQLState:" + e.getSQLState());
System.out.println("Error Code:" + e.getErrorCode());
System.out.println("Message:" + e.getMessage());
Throwable t = e.getCause();
while(t != null) {
System.out.println("Cause:" + t);
t = t.getCause();
}
e = e.getNextException();
} while (e != null);
}
and the Output is :
SQLState:null
Error Code:0
Message:Failed on insert row