Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 40FD09FB43C for ; Fri, 12 Jan 2007 10:01:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 29476-10 for ; Fri, 12 Jan 2007 10:01:15 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.226]) by postgresql.org (Postfix) with ESMTP id B089E9FB2F5 for ; Fri, 12 Jan 2007 10:01:15 -0400 (AST) Received: by wr-out-0506.google.com with SMTP id i28so656594wra for ; Fri, 12 Jan 2007 06:01:14 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=CSWLrluMZiz25CYwfSUm0gc9zXQF3GAKFZKja2bNYR+a9tY/+0MtDukHglv6zWBVQKXtwyS7K+ZhY6rvL0yj91VcQbVjX8zH3GONxht/Uz34LGAwhYvclaVFVquU35kMQ12Xi0+kyiymxxo3ZlIVokdrHsCXZxsBG80ckefV2vM= Received: by 10.78.149.15 with SMTP id w15mr277204hud.1168610472993; Fri, 12 Jan 2007 06:01:12 -0800 (PST) Received: by 10.78.90.20 with HTTP; Fri, 12 Jan 2007 06:01:12 -0800 (PST) Message-ID: <3fccaa690701120601g78c45dfcj3547085875e5966a@mail.gmail.com> Date: Fri, 12 Jan 2007 08:01:12 -0600 From: "Andres Olarte" To: "vasylenko@uksatse.org.ua" Subject: Re: Cc: pgsql-jdbc@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/89 X-Sequence-Number: 16454 Two things that you might check for, but I think your problem is number 2. 1- Is the ResultSet updateable? Basically you create your Statement like this: stmt=conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE) 2- Does your table have a oid and a primary key defined? Are you selecting them in the ? You need to select those two (or at least one, I'm not sure) in the ResultSet to be able to insert. Just do a "SELECT * FROM table.schema LIMIT 1" to be sure On 1/12/07, vasylenko@uksatse.org.ua wrote: > > > > Ok, Dave > your question: > >Can you explain this more, or send a small test case. There should be > >no reason to get a primary key simply to move to insert row. > >We do need the primary key in the dataset, but other than that we > >shouldn't fail on move to insert row ? > > I have just trased into moveToInsertRow() method step by step. > > Firstly, it try to find oid field in result set > Than it looking for Primary Key in result. > > That's all what I have done. > > there 3 method > moveToInsertRow() > checkUpdateblet() > isUpdateable() > > the exception is thrown in the last method. > > > public synchronized void moveToInsertRow() > throws SQLException > { > checkUpdateable(); > > if (insertStatement != null) > { > insertStatement = null; > } > > > // make sure the underlying data is null > clearRowBuffer(false); > > onInsertRow = true; > doingUpdates = false; > > } > > > > private void checkUpdateable() throws SQLException > { > checkClosed(); > > if (!isUpdateable()) > throw new PSQLException(GT.tr("ResultSet is not updateable. > The query that generated this result set must select only one table, and > must select all primary keys from that table. See the JDBC 2.1 API > Specification, section 5.6 for more details."), > PSQLState.INVALID_CURSOR_STATE); > > if (updateValues == null) > { > // allow every column to be updated without a rehash. > updateValues = new HashMap((int)(fields.length / 0.75), 0.75f); > } > } > > > > > > > boolean isUpdateable() throws SQLException > { > checkClosed(); > > if (resultsetconcurrency == ResultSet.CONCUR_READ_ONLY) > throw new PSQLException(GT.tr("ResultSets with concurrency > CONCUR_READ_ONLY cannot be updated."), > PSQLState.INVALID_CURSOR_STATE); > > if (updateable) > return true; > > if ( Driver.logDebug ) > Driver.debug("checking if rs is updateable"); > > parseQuery(); > > if ( singleTable == false ) > { > if ( Driver.logDebug ) > Driver.debug("not a single table"); > return false; > } > > if ( Driver.logDebug ) > Driver.debug("getting primary keys"); > > // > // Contains the primary key? > // > > primaryKeys = new Vector(); > > // this is not stricty jdbc spec, but it will make things much > faster if used > // the user has to select oid, * from table and then we will just > use oid > > > usingOID = false; > int oidIndex = 0; > try > { > oidIndex = findColumn( "oid" ); > } > catch (SQLException l_se) > { > //Ignore if column oid isn't selected > } > int i = 0; > > > // if we find the oid then just use it > > //oidIndex will be >0 if the oid was in the select list > if ( oidIndex > 0 ) > { > i++; > primaryKeys.add( new PrimaryKey( oidIndex, "oid" ) ); > usingOID = true; > } > else > { > // otherwise go and get the primary keys and create a hashtable > of keys > String[] s = quotelessTableName(tableName); > String quotelessTableName = s[0]; > String quotelessSchemaName = s[1]; > java.sql.ResultSet rs = ((java.sql.Connection) > connection).getMetaData().getPrimaryKeys("", quotelessSchemaName, > quotelessTableName); > for (; rs.next(); i++ ) > { > String columnName = rs.getString(4); // get the columnName > int index = findColumn( columnName ); > > if ( index > 0 ) > { > primaryKeys.add( new PrimaryKey(index, columnName ) ); > // get the primary key information > } > } > > rs.close(); > } > > if ( Driver.logDebug ) > Driver.debug( "no of keys=" + i ); > > if ( i < 1 ) > { > throw new PSQLException(GT.tr("No primary key found for table > {0}.", tableName), > PSQLState.DATA_ERROR); > } > > updateable = primaryKeys.size() > 0; > > if ( Driver.logDebug ) > Driver.debug( "checking primary key " + updateable ); > > return updateable; > } > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >