Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 688E69FA594 for ; Wed, 10 Jan 2007 08:06:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 69489-06 for ; Wed, 10 Jan 2007 08:06:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by postgresql.org (Postfix) with SMTP id 875829FB1C6 for ; Wed, 10 Jan 2007 08:06:41 -0400 (AST) Received: (qmail 14398 invoked from network); 10 Jan 2007 12:06:39 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.14?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 10 Jan 2007 12:06:39 -0000 In-Reply-To: References: Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=UTF-8; delsp=yes; format=flowed Message-Id: <6FBFEA2D-BAE3-4420-9685-3FA10E070A54@fastcrypt.com> Cc: pgsql-jdbc@postgresql.org Content-Transfer-Encoding: quoted-printable From: Dave Cramer Subject: Re: How to Insert the Row in ResultSet by moveToInsertRow() ... insertRow()? Date: Wed, 10 Jan 2007 07:06:45 -0500 To: vasylenko@uksatse.org.ua X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/65 X-Sequence-Number: 16430 On 10-Jan-07, at 5:47 AM, vasylenko@uksatse.org.ua wrote: > > > Hello! > |---------------------------------------------------------------------=20= > -----| > | =20= > | > | =20= > | > | =20= > | > | =20= > | > | =20= > | > | =20= > | > | =20= > | > | =20= > | > | I've got the Postgre database and table =20 > insdide | > | =20= > | > | =20 > code: | > | =20= > | > | =20= > | > | =20= > | > | =20= > | > | CREATE TABLE =20 > groups | > | =20 > ( | > | id int4 NOT NULL DEFAULT nextval=20 > ('seq_group_id'::regclass), | > | g_name text NOT =20 > NULL, | > | CONSTRAINT i_group PRIMARY KEY =20 > (id) | > | ) =20= > | > | WITHOUT =20 > OIDS; | > | ALTER TABLE groups OWNER TO =20 > vasylenko; | > | COMMENT ON TABLE groups IS '=D0=93=D1=80=D1=83=D0=BF=D0=BF=D1=8B= =20 > =D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2 = (=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82, =D1=81=D0=BC=D0=B5=D0=BD=D0=B0 = | > | ...)'; =20= > | > | =20= > | > | =20= > | > | =20= > | > | =20= > | > | As You can see: 2 =20 > fields | > | id - it's an autofill =20 > field. | > | =20= > | > | But when I try to insert the new Row in code putting =20 > under It | > | generete the SQLException, that "id" filed was not found =20 > in | > | ResultSet. But it mustn't be there as for =20 > me. | > | I created the id field with default value from the =20 > sequence | > | =20 > code: | > | =20= > | > | =20= > | > | =20= > | > | CREATE SEQUENCE =20 > seq_group_id | > | INCREMENT =20 > 1 | > | MINVALUE =20 > 1 | > | MAXVALUE =20 > 9223372036854775807 | > | START =20 > 26 | > | CACHE =20 > 1; | > | ALTER TABLE seq_group_id OWNER TO =20 > vasylenko; | > | =20= > | > | =20= > | > | =20= > | > | =20= > | > | The Code =20 > is: | > | =20 > code: | > | =20= > | > | =20= > | > | =20= > | > | ResultSet =20 > rs; | > | Statement stat =20 > =3D | > | conn.createStatement=20 > (ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CO| > | =20 > NCUR_UPDATABLE); | You only selected g_name , not id, g_name Dave > | rs =3D stat.executeQuery("Select g_name FROM =20 > groups"); | > | try=20 > { | > | rs.moveToInsertRow=20 > (); | > | /=20 > ** | > | ** !!!!!!!The exception generated =20 > there !!!!!!!!! | > | =20 > */ | > | } =20= > | > | catch(SQLException ex)=20 > { | > | =20= > | > | System.out.print(ex.getMessage()=20 > +"\n"); | > | =20 > return; | > | } =20= > | > | =20= > | > | try=20 > { | > | String temp =3D "New =20 > Group"; | > | =20= > | > | rs.updateObject(i+1, =20 > temp); | > | } =20= > | > | =20= > | > | catch(SQLException ex) =20 > { | > | =20= > | > | System.out.print(ex.getMessage()=20 > +"\n"); | > | =20 > return; | > | } =20= > | > | =20= > | > | =20= > | > | try=20 > { | > | rs.insertRow=20 > (); | > | } =20= > | > | catch(SQLException =20 > ex) | > | =20 > { | > | =20= > | > | System.out.print(ex.getMessage()=20 > +"\n"); | > | =20= > | > | } =20= > | > | =20= > | > | =20= > | > | =20= > | > | =20= > | > | =20= > | > | I don't neew to make the ResultSet with both fields... =20 > 'cos I use| > | this ResultSet Data in JTable table =20 > model. | > | How to solve the =20 > problem? | > | =20 > Thanks. | > | =20= > | > | =20= > | > | =20= > | > | =20= > | > |---------------------------------------------------------------------=20= > -----| > > > > > ---------------------------(end of =20 > broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster