我使用对CachedRowSetImpl,我可以从数据库中获取数据,但我不能插入。
这是代码:
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)无法插入行上
我曾尝试一个JdbcRowSetImpl而是对CachedRowSetImpl的,它的做工精细
更新:我用这个代码来捕获有关异常的更多详细信息:
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
消息:无法插入行上