我正在使用CachedRowSetImpl,我可以從數據庫中獲取數據,但我無法插入。使用CachedRowSet插入行失敗
這是代碼:
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();
}
}
它拋出異常:線程 「main」 值java.sql.SQLException
例外:在com.sun.rowset無法插入行上 .CachedRowSetImpl.insertRow(CachedRowSetImpl.java:5462) 在NewClass.main(NewClass.java:32)
我已經試過JdbcRo wSetImpl而是對CachedRowSetImpl的,它的做工精細
UPDATE:我用這個代碼來捕獲有關異常的更多詳細信息:
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);
}
,輸出是:
SQLSTATE:空
錯誤代碼:0
消息:插入行失敗
您需要檢查整個異常。請參閱以下說明以了解如何執行此操作:http://wiki.apache.org/db-derby/UnwindExceptionChain。完成後請詳細更新您的問題。 – 2012-07-22 17:33:18
謝謝@BryanPendleton :),我更新了我的問題,但它看起來沒有更多詳細信息 – 2012-07-22 21:19:47
嘗試做e.printStackTrace()內catch()塊 – 2012-07-23 13:41:19