From: | vasylenko(at)uksatse(dot)org(dot)ua |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | How to Insert the Row in ResultSet by moveToInsertRow() ... insertRow()? |
Date: | 2007-01-10 10:47:57 |
Message-ID: | OFD168223B.F807FA6D-ONC225725F.003AF87A-C225725F.003B52A4@UKCC.UKSATSE |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Hello!
|--------------------------------------------------------------------------|
| |
| |
| |
| |
| |
| |
| |
| |
| I've got the Postgre database and table insdide |
| |
| code: |
| |
| |
| |
| |
| CREATE TABLE groups |
| ( |
| id int4 NOT NULL DEFAULT nextval('seq_group_id'::regclass), |
| g_name text NOT NULL, |
| CONSTRAINT i_group PRIMARY KEY (id) |
| ) |
| WITHOUT OIDS; |
| ALTER TABLE groups OWNER TO vasylenko; |
| COMMENT ON TABLE groups IS 'Группы работников (объект, смена |
| ...)'; |
| |
| |
| |
| |
| As You can see: 2 fields |
| id - it's an autofill field. |
| |
| But when I try to insert the new Row in code putting under It |
| generete the SQLException, that "id" filed was not found in |
| ResultSet. But it mustn't be there as for me. |
| I created the id field with default value from the sequence |
| code: |
| |
| |
| |
| CREATE SEQUENCE seq_group_id |
| INCREMENT 1 |
| MINVALUE 1 |
| MAXVALUE 9223372036854775807 |
| START 26 |
| CACHE 1; |
| ALTER TABLE seq_group_id OWNER TO vasylenko; |
| |
| |
| |
| |
| The Code is: |
| code: |
| |
| |
| |
| ResultSet rs; |
| Statement stat = |
| conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CO|
| NCUR_UPDATABLE); |
| rs = stat.executeQuery("Select g_name FROM groups"); |
| try{ |
| rs.moveToInsertRow(); |
| /** |
| ** !!!!!!!The exception generated there !!!!!!!!! |
| */ |
| } |
| catch(SQLException ex){ |
| |
| System.out.print(ex.getMessage()+"\n"); |
| return; |
| } |
| |
| try{ |
| String temp = "New Group"; |
| |
| rs.updateObject(i+1, temp); |
| } |
| |
| catch(SQLException ex) { |
| |
| System.out.print(ex.getMessage()+"\n"); |
| return; |
| } |
| |
| |
| try{ |
| rs.insertRow(); |
| } |
| catch(SQLException ex) |
| { |
| |
| System.out.print(ex.getMessage()+"\n"); |
| |
| } |
| |
| |
| |
| |
| |
| I don't neew to make the ResultSet with both fields... 'cos I use|
| this ResultSet Data in JTable table model. |
| How to solve the problem? |
| Thanks. |
| |
| |
| |
| |
|--------------------------------------------------------------------------|
From | Date | Subject | |
---|---|---|---|
Next Message | Dave Cramer | 2007-01-10 12:04:39 | Re: Connection Problem |
Previous Message | Rich Rutkowski | 2007-01-10 04:46:35 | Connection Problem |