You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2009/03/02 14:51:56 UTC

[jira] Commented: (DERBY-4076) rowset.insertRow() does not working

    [ https://issues.apache.org/jira/browse/DERBY-4076?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12677988#action_12677988 ] 

Knut Anders Hatlen commented on DERBY-4076:
-------------------------------------------

I think the problem here is that the ID column is not nullable, and CachedRowSetImpl.insertRow() requires that all non-nullable columns have been given a value. This is a limitation in com.sun.rowset.CachedRowSetImpl, which is not part of Derby. You may be able to work around it by removing the ID column from the select list in RequestLoader.strGetListEntries, or by generating the ID value manually instead of using GENERATED ALWAYS AS IDENTITY. Using Derby's updatable result sets directly should also work, as they don't have this limitation.

> rowset.insertRow() does not working
> -----------------------------------
>
>                 Key: DERBY-4076
>                 URL: https://issues.apache.org/jira/browse/DERBY-4076
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions: 10.4.2.0
>         Environment: windows 32b eclipse ganymede 
>            Reporter: jaoued zahraoui
>            Priority: Critical
>             Fix For: 10.4.2.1
>
>
> creating table with this SQL request : 
> CREATE table APP.ADDRESS (
>     ID          INTEGER NOT NULL 
>                 PRIMARY KEY GENERATED ALWAYS AS IDENTITY 
>                 (START WITH 1, INCREMENT BY 1),
>     LASTNAME    VARCHAR(30), 
>     FIRSTNAME   VARCHAR(30),
>     MIDDLENAME  VARCHAR(30),
>     PHONE       VARCHAR(20),
>     EMAIL       VARCHAR(30), 
>     ADDRESS1    VARCHAR(30),
>     ADDRESS2    VARCHAR(30),
>     CITY        VARCHAR(30),
>     STATE       VARCHAR(30),
>     POSTALCODE  VARCHAR(20),
>     COUNTRY     VARCHAR(30) )
> trying this to run this code : 
> 	public static void main(String[] args) {
> 		CachedRowSetImpl res = null;
> 		try {
> 			res = new CachedRowSetImpl();
> 			res.setCommand(RequestLoader.strGetListEntries);
> 			res.setTableName("ADDRESS");
> 			res.setType(ResultSet.TYPE_FORWARD_ONLY);
> 			res.setConcurrency(ResultSet.CONCUR_UPDATABLE);
> 			Connection conn = Dbconnect.getInstance().getDbConnection();
> 			res.execute(conn);
> 			
> 			
> 			// Check ResultSet's updatability
> 			if (res.getConcurrency() == ResultSet.CONCUR_READ_ONLY) {
> 				System.out.println("ResultSet non-updatable.");
> 			} else {
> 				System.out.println("ResultSet updatable.");
> 			}
> 			// Move the cursor to the insert row
> 			res.moveToInsertRow();
> 			// Set the new first name and last name
> 			// System.out.println("ID : " + rs.getInt("ID"));
> 			res.updateString("LASTNAME", "aaaaa");
> 			res.updateString("FIRSTNAME", "aaaaa");
> 			res.updateString("MIDDLENAME", "aaaaa");
> 			res.updateString("PHONE", "aaaaa");
> 			res.updateString("EMAIL", "aaaaa");
> 			res.updateString("ADDRESS1", "aaaaa");
> 			res.updateString("ADDRESS2", "aaaaa");
> 			res.updateString("CITY", "aaaaa");
> 			res.updateString("STATE", "aaaaa");
> 			res.updateString("POSTALCODE", "aaaaa");
> 			res.updateString("COUNTRY", "aaaaa");
> 			// Store the insert into database
> 			res.insertRow();
> 			// Move the curesor back to the current row
> 			res.moveToCurrentRow();
> 			System.out.println("Row inserted ok.");
> 			// Close ResultSet and Statement
> 			res.close();
> 		} catch (Exception e) {
> 			e.printStackTrace();
> 		}
> 	}
> resuting in :
> ResultSet updatable.
> java.sql.SQLException: Échec de l'insertion de ligne
> 	at com.sun.rowset.CachedRowSetImpl.insertRow(Unknown Source)
> 	at fr.free.zahraoui.test.database.DerbyRowSetInsertRow.main(DerbyRowSetInsertRow.java:49)
> DerbyRowSetInsertRow.java:49 represent : res.insertRow();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.