Exception: No primary keys?

Поиск
Список
Период
Сортировка
Искать

Exception: No primary keys?

От:
"Han" <zhouhanok@vip.sina.com>
Дата:
pgsql-jdbc

	A simplest test failed when I use postgresql and pgsql-jdbc driver which were build from postgresql7.3b5 source code.
    The test code is:
..
     14         try{
     15             Class.forName(strDrv);
     16             conn = DriverManager.getConnection(strUrl, "postgl", "");
     17             stmt = conn.createStatement();
     18             rs = stmt.executeQuery(strSql);
     19             while (rs.next())
     20             {
     21                 System.out.println(rs.getString(1));
     22             }
     23             //rs.beforeFirst();
     24             while (rs.previous())
     25             {
     26                 System.out.println(rs.getString(1));
     27             }
     28             rs.moveToInsertRow();
     29             rs.updateInt("a", 100);
     30             rs.insertRow();
     31         } catch(Exception e){
     32             System.out.println(e.toString());
     33         }

   	The table "test" has only two columns(a int, b varchar) and no primary keys.
	The error message is: No primary keys.
	It's all right with line 28,29 and 30 commented out.
	It will also succedd when the table "test" has a primary key.
    Can you tell me why?
	My environment is:
	redhat 7.3
	j2sdk1.4.1_01
	ant1.5.1

	Thanks and regards,
        
 				

        Han
        zhouhanok@vip.sina.com
          2002-12-02



Re: Exception: No primary keys?

От:
Dave Cramer <Dave@micro-automation.net>
Дата:
Han,

In order for the updateXXX to work it needs a primary key. This is in
the spec. Furthermore, under the covers this is what is going on.

when you call updateXXX, the driver does 

update foo set column=newval where primarykey=val

It needs the primary key to be able to figure out which row to update.

Dave
On Mon, 2002-12-02 at 03:43, Han wrote:
> pgsql-jdbc
> 
> 	A simplest test failed when I use postgresql and pgsql-jdbc driver which were build from postgresql7.3b5 source code.
>     The test code is:
> ..

> -- 
> Dave Cramer 
> Cramer Consulting
>      14         try{
>      15             Class.forName(strDrv);
>      16             conn = DriverManager.getConnection(strUrl, "postgl", "");
>      17             stmt = conn.createStatement();

> -- 
> Dave Cramer 
> Cramer Consulting
>      18             rs = stmt.executeQuery(strSql);
>      19             while (rs.next())
>      20             {
>      21                 System.out.println(rs.getString(1));
>      22             }
>      23             //rs.beforeFirst();
>      24             while (rs.previous())
>      25             {
>      26                 System.out.println(rs.getString(1));
>      27             }
>      28             rs.moveToInsertRow();
>      29             rs.updateInt("a", 100);
>      30             rs.insertRow();
>      31         } catch(Exception e){
>      32             System.out.println(e.toString());
>      33         }
> 
>    	The table "test" has only two columns(a int, b varchar) and no primary keys.
> 	The error message is: No primary keys.
> 	It's all right with line 28,29 and 30 commented out.
> 	It will also succedd when the table "test" has a primary key.
>     Can you tell me why?
> 	My environment is:
> 	redhat 7.3
> 	j2sdk1.4.1_01
> 	ant1.5.1
> 
> 	Thanks and regards,
>         
>  				
> 
>         Han
>         zhouhanok@vip.sina.com
>           2002-12-02
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
-- 
Dave Cramer 

Re: Exception: No primary keys?

От:
"Han" <zhouhanok@vip.sina.com>
Дата:
Dave Cramer,

	Sounds reasonable. But I still have some questions.
	First, what I did is just to insert a row, not update. It goes wrong when calling rs.moveToInsertRow().
	Second, I think that the driver can determine which row to update by using a cursor.
	Thirdly, this simple test works well with Ms Sql Server. How can they implement it? And I remember that it worked well with a previous postgresql jdbc driver months ago.
	Lastly, if it's in the spec, please tell me the page or an address. I read the ResultSet related topics in java.sql api reference and could not find such a topic.
    Thanks and regards,

>Han,
>
>In order for the updateXXX to work it needs a primary key. This is in
>the spec. Furthermore, under the covers this is what is going on.
>
>when you call updateXXX, the driver does
>
>update foo set column=newval where primarykey=val
>
>It needs the primary key to be able to figure out which row to update.
>
>Dave
>On Mon, 2002-12-02 at 03:43, Han wrote:
>> pgsql-jdbc
>>
>> 	A simplest test failed when I use postgresql and pgsql-jdbc driver which were build from postgresql7.3b5 source code.
>>     The test code is:
>> ..
>>      28             rs.moveToInsertRow();
>>      29             rs.updateInt("a", 100);
>>      30             rs.insertRow();
>>      31         } catch(Exception e){
>>      32             System.out.println(e.toString());
>>      33         }
>>
>>    	The table "test" has only two columns(a int, b varchar) and no primary keys.
>> 	The error message is: No primary keys.
>> 	It's all right with line 28,29 and 30 commented out.
>> 	It will also succedd when the table "test" has a primary key.
>>     Can you tell me why?
>> 	My environment is:
>> 	redhat 7.3
>> 	j2sdk1.4.1_01
>> 	ant1.5.1
>>
>> 	Thanks and regards,
>>         
>>  				
>>
>>         Han
>>         zhouhanok@vip.sina.com
>>           2002-12-02
>--
>Dave Cramer 
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
				
        Han
        zhouhanok@vip.sina.com
          2002-12-03




FAQ