Cleare
asked on
problem with insert statements in JDBC
Not sure if this is a Java question or a MySql question.
I'm trying basic insert statements and am using a totorial on the sun web page. From what I can see the code is identical to that on the tutorial and I have just altered it to fit the names of my own db.
Statement stmt = C.createStatement(ResultSe t.TYPE_SCR OLL_SENSIT IVE,
ResultSet.CONCUR_UPDATABLE );
ResultSet uprs = stmt.executeQuery("SELECT entrykey, headword, part_of_speech, crossref, gramm_info FROM irishentries");
uprs.moveToInsertRow();
uprs.updateInt("entrykey", 63893);
uprs.updateString("headwor d", "Liz");
uprs.updateString("part_of _speech", "Clear");
uprs.updateString("crossre f", "was");
uprs.updateString("gramm_i nfo", "here");
uprs.insertRow();
uprs.updateInt("entrykey", 63894);
uprs.updateString("headwor d", "Kona_Decaf");
uprs.updateString("part_of _speech", "blah");
uprs.updateString("crossre f","none" );
uprs.updateString("gramm_i nfo","none here either" );
uprs.insertRow();
uprs.beforeFirst();
System.out.println("Table iIRISHENTRIES after insertion:");
while (uprs.next()) {
int ekey = uprs.getInt("entrykey");
String headwd = uprs.getString("headword") ;
String pofs = uprs.getString("part_of-sp eech");
String cross = uprs.getString("crossref") ;
String grinf = uprs.getString("gramm_info ");
System.out.print(ekey + " " + headwd + " " + pofs);
System.out.println(" " + cross + " " + grinf);
}
It's compiling correctly but I'm getting the response
SQLException: ResultSet is from UPDATE. No Data
SQLState: S1000
VendorError: 0
from MySql.
Any ideas where I'm going wrong?
thanks
liz
I'm trying basic insert statements and am using a totorial on the sun web page. From what I can see the code is identical to that on the tutorial and I have just altered it to fit the names of my own db.
Statement stmt = C.createStatement(ResultSe
ResultSet.CONCUR_UPDATABLE
ResultSet uprs = stmt.executeQuery("SELECT entrykey, headword, part_of_speech, crossref, gramm_info FROM irishentries");
uprs.moveToInsertRow();
uprs.updateInt("entrykey",
uprs.updateString("headwor
uprs.updateString("part_of
uprs.updateString("crossre
uprs.updateString("gramm_i
uprs.insertRow();
uprs.updateInt("entrykey",
uprs.updateString("headwor
uprs.updateString("part_of
uprs.updateString("crossre
uprs.updateString("gramm_i
uprs.insertRow();
uprs.beforeFirst();
System.out.println("Table iIRISHENTRIES after insertion:");
while (uprs.next()) {
int ekey = uprs.getInt("entrykey");
String headwd = uprs.getString("headword")
String pofs = uprs.getString("part_of-sp
String cross = uprs.getString("crossref")
String grinf = uprs.getString("gramm_info
System.out.print(ekey + " " + headwd + " " + pofs);
System.out.println(" " + cross + " " + grinf);
}
It's compiling correctly but I'm getting the response
SQLException: ResultSet is from UPDATE. No Data
SQLState: S1000
VendorError: 0
from MySql.
Any ideas where I'm going wrong?
thanks
liz
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Does your driver support jdbc 2.0?
if so, i would also do like slava_k suggests above. the driver seems to be a little screwy especially when doing updates/inserts.