I try to insert a row using a ResultSet into a H2 database (1.4.182). By invoking insertRow the program throws an exception. And I have no clue what the problem is.
The exception is:
The result set is not updatable. The query must select all columns from a unique key.
Only one table may be selected. [90127-182]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.message.DbException.get(DbException.java:144)
at org.h2.jdbc.JdbcResultSet.getUpdatableRow(JdbcResultSet.java:3081)
at org.h2.jdbc.JdbcResultSet.insertRow(JdbcResultSet.java:2966)
at JdbcResultSetUpdate.main(JdbcResultSetUpdate.java:26)
The SQL statement the program executes to create the ResultSet is:
"select NAME from TEST.TST_DOZENT"
TST_DOZENT is created by the statement:
"CREATE TABLE TEST.TST_DOZENT (NAME VARCHAR(50))", "Create TST_DOZENT-Tab"
So the query-statement doesn't use a system-table, the table has no primary-key.
The java statement object is created by:
con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
I can't fugure out what the problem is or what I'm doing wrong.
I would appreciate any help.
Thany you for reading.
The table needs to have a primary key or unique index, and the query needs to contain that column. Example:
CREATE TABLE TEST.TST_DOZENT (ID PRIMARY KEY, NAME VARCHAR(50));
SELECT ID, NAME FROM TEST.TST_DOZENT;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.