• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Insertion Of Data

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I am using MS-access as backend and jdbc connection for transfering data from a servlet.But it gives an error saying that:SQL Exception, no resultset was created.
The Select ,Create table statement were executed successful.
Only the Insert statement is not executing correctly.
Navi
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The insert statement won't create a ResultSet. What is the actual error?
 
Navtaj Singh
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Thanks for answering
Well here is the code bit ,:-
String str="create table student(stid Number,stname Number)";
res=stm.executeQuery(str);
PreparedStatement pstm=con.prepareStatement("INSERT INTO student (stid,stname) VALUES (?,?)");
pstm.setInt(1,9);
pstm.setInt(2,6);
pstm.executeUpdate();

ResultSet res1=stm.executeQuery("SELECT stid,stname FROM student");
out.println("<html>");
...
...

The error is :-
SQLException caught : No ResultSet was produced .
When i check the ms-access database,the table gets created
but the "Insert" statement does not execute.
ie.
Thanks
Navi.
 
Navtaj Singh
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahoy! Anybody Ahoy!
Please Help me out!
Navi
[This message has been edited by Navtaj Singh (edited February 16, 2001).]
[This message has been edited by Navtaj Singh (edited February 16, 2001).]
 
Rancher
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, this topic is about 4 years old, but I'm going to answer it anyway.

The reason the executeQuery() is not producing a result set is because you're making an update, not pulling information with a query.

You should use the executeUpdate() method with your update when you are creating a table or inserting data. The executeUpdate() method returns an int, I think, being the status of the update.



That should update the DB. You don't even need to return anything if you don't want to. There will not be a result set.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change:

ResulSet RS = statment.executeQuery(...)
to
int RS = stmt.executeUpdate(...)

That should sort it.
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic