pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedInsert Row to ResultSet problem....java.sql.SQLException: No Primary Keys
2+ messages / 2 participants
[nested] [flat]
* Insert Row to ResultSet problem....java.sql.SQLException: No Primary Keys
@ 2003-12-16 15:24 Jason L. van Brackel <jasonvanbrackel@speakeasy.net>
0 siblings, 1 reply; 2+ messages in thread
From: jasonvanbrackel@speakeasy.net @ 2003-12-16 15:24 UTC (permalink / raw)
To: pgsql-jdbc@postgresql.org
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",
"5432");
// 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");
try{
ResultSet addressInfo = null; // ResultSet for Address Info
sql = "SELECT * FROM address;";
addressInfo = migr.queryStatement(migr.postgreSQLConnection, sql);
addressInfo.moveToInsertRow();
..... this is where I get this exception
java.sql.SQLException: No Primary Keys
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.isUpdateable(AbstractJdbc2ResultSet.java:1363)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.moveToInsertRow(AbstractJdbc2ResultSet.java:697)
at com.cimconsultants.EFRMigration.MigrationUtil.main(MigrationUtil.java:62)
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 =
con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(SQLStatement);
}catch(SQLException ex) {
System.out.println("Query SQL Exception");
ex.printStackTrace();
System.exit(0);
}
return rs;
}
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
driver.
Thanks in advance,
Jason L. van Brackel
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [JDBC] Insert Row to ResultSet problem....java.sql.SQLException: No Primary Keys
@ 2003-12-22 23:50 Paul Thomas <paul@tmsl.demon.co.uk>
parent: Jason L. van Brackel <jasonvanbrackel@speakeasy.net>
0 siblings, 0 replies; 2+ messages in thread
From: Paul Thomas @ 2003-12-22 23:50 UTC (permalink / raw)
To: pgsql-sql
On 16/12/2003 15:24 Jason L. van Brackel wrote:
> [snip]
> ..... this is where I get this exception
> java.sql.SQLException: No Primary Keys
~~~~~~~~~~~~~~~
> at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.isUpdateable(AbstractJdbc2ResultSet.java:1363)
> at
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.moveToInsertRow(AbstractJdbc2ResultSet.java:697)
> at
> com.cimconsultants.EFRMigration.MigrationUtil.main(MigrationUtil.java:62)
> [snip]
> 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
> driver.
A total shot in the dark but do you have a primary key on the table?
--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants |
http://www.thomas-micro-systems-ltd.co.uk |
+------------------------------+---------------------------------------------+
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-12-22 23:50 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-12-16 15:24 Insert Row to ResultSet problem....java.sql.SQLException: No Primary Keys Jason L. van Brackel <jasonvanbrackel@speakeasy.net>
2003-12-22 23:50 ` Paul Thomas <paul@tmsl.demon.co.uk>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox