Solved

problem with insert statements in JDBC

Posted on 2002-03-13
3
248 Views
Last Modified: 2010-03-31
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(ResultSet.TYPE_SCROLL_SENSITIVE,
                                     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("headword", "Liz");
      uprs.updateString("part_of_speech", "Clear");
      uprs.updateString("crossref", "was");
      uprs.updateString("gramm_info", "here");
      uprs.insertRow();

      uprs.updateInt("entrykey", 63894);      
      uprs.updateString("headword", "Kona_Decaf");
      uprs.updateString("part_of_speech", "blah");
      uprs.updateString("crossref","none" );
      uprs.updateString("gramm_info","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-speech");
          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
0
Comment
Question by:Cleare
3 Comments
 
LVL 2

Accepted Solution

by:
Slava_K earned 50 total points
ID: 6861897
why not do just a simple insert?
String x, y, z;
x = "x";
y = "y";
z = "z";

String strSQL = "Insert into TBL(x,y,z) Values(" +x+ "," + y + "," + z " ")";

Statement statment = connection.createStatement();
            rs = statment.executeQuery(strSQL);
            connection.commit();
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6862038
i'm guessing you're using org.gjt.mm.mysql driver...

if so, i would also do like slava_k suggests above.  the driver seems to be a little screwy especially when doing updates/inserts.
0
 
LVL 6

Expert Comment

by:kotan
ID: 6863453
Does your driver support jdbc 2.0?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is the latest versions eclipse neon 2 139
solarwind tftp server 2 44
split string containing \r\n in Java 46 38
diffSum example 4 23
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now