Skip site navigation (1) Skip section navigation (2)

Insert Row to ResultSet No Primary Keys

From: "Jason L(dot) van Brackel" <jasonvanbrackel(at)speakeasy(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Insert Row to ResultSet No Primary Keys
Date: 2003-12-16 18:12:23
Message-ID: W9833916167222581071598343@webmail4 (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
I sent this through google groups, but then found I could join the mailing list directly sorry about the repost, but I added the table information to this one.....

I'm migrating data from a poorly modeled MS Access 2000 DB to newly
developed PosgreSQL 7.4 DB. I'm connecting to the Access database
using a jdbc-odbc bridge driver. I'm connectin the postgreSQL DB
using the pg74jdbc3.jar driver.

public static void main(String[] args) {
String[] schools; // Array of SchoolCodes

MigrationUtil migr = new MigrationUtil();
// Connect to the Access Database
migr.connectToAccess("Access", "C:\\Working\\Access\\Access.mdb");
// Connect to the PostgreSQL Database
migr.connectToPostgreSQL("PostgreSQL_Test", "cimTux.cim.internal",
// Get Schools List
System.out.println("Getting List of Schools from access.mdb");
schools = migr.resultSetToStringArray(migr.queryStatement(migr.ODBCConnection,
"SELECT ftno FROM tblmst WHERE ftcode ='SC'"));
// Start the Main Loop
for(int i = 0; i < schools.length; i++)
String currentSchool = schools[i]; // current School Code
ResultSet rs = null; // reusable ResultSet variable
String sql = null; // reusable SQL Statement String
int schoolContactID = 0; // current School ContactID
int schoolAddressID = 0; // current School AddressID
int eduOrgID = 0; // current EduOrganization ID
System.out.println("Current School: " + currentSchool);
// Get School information
sql = "SELECT FtDes, LenderAddress1, LenderCity, LenderState,
LenderZip, " + "LenderAddress2, fsch_code, EINNo FROM tblmst WHERE
ftcode = 'SC' AND ftno = '" + currentSchool + "';";
rs = migr.queryStatement(migr.ODBCConnection, sql);
// Update school address information
System.out.println("Migrating School Address Info");
ResultSet addressInfo = null; // ResultSet for Address Info
sql = "SELECT * FROM address;";
addressInfo = migr.queryStatement(migr.postgreSQLConnection, sql);
..... this is where I get this exception
java.sql.SQLException: No Primary Keys
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.isUpdateable(
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.moveToInsertRow(
at com.cimconsultants.EFRMigration.MigrationUtil.main(

Here is the queryStatement(Connection, String) Method

private ResultSet queryStatement(Connection con, String SQLStatement)
ResultSet rs = null;
try {
System.out.println("Query: " + SQLStatement);
Statement stmt =
rs = stmt.executeQuery(SQLStatement);
}catch(SQLException ex) {
System.out.println("Query SQL Exception");
return rs;

Here is the table from psql:
PostgreSQL_Test=# \d address
                                          Table "public.address"
     Column      |         Type          |                           Modifiers
 addressid       | bigint                | not null default nextval('public.address_addressid_seq'::text)
 address1        | character varying(50) | not null
 address2        | character varying(50) |
 address3        | character varying(50) |
 city            | character varying(50) | not null
 stateprovidence | character varying(10) | not null
 postalcode      | character varying(12) | not null
 country         | character varying(50) | not null
    "address_pkey" primary key, btree (addressid)

I'm experienced with Java, but very new to JDBC and PostgreSQL. I'm
using the JDK 1.4, PostgreSQL 7.4, and the binary pg74jdbc3.jar

Thanks in advance,

Jason L. van Brackel


pgsql-jdbc by date

Next:From: Kris JurkaDate: 2003-12-16 19:20:17
Subject: Re: Insert Row to ResultSet
Previous:From: Peter EisentrautDate: 2003-12-16 18:00:25
Subject: Re: sort question

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group