This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Insertion  Of  Data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Insertion  Of  Data" Watch "Insertion  Of  Data" New topic

Insertion Of Data

Navtaj Singh
Ranch Hand

Joined: Jan 30, 2001
Posts: 37
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.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
The insert statement won't create a ResultSet. What is the actual error?

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Navtaj Singh
Ranch Hand

Joined: Jan 30, 2001
Posts: 37
Hi! Thanks for answering
Well here is the code bit ,:-
String str="create table student(stid Number,stname Number)";
PreparedStatement pstm=con.prepareStatement("INSERT INTO student (stid,stname) VALUES (?,?)");

ResultSet res1=stm.executeQuery("SELECT stid,stname FROM student");

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.
Navtaj Singh
Ranch Hand

Joined: Jan 30, 2001
Posts: 37
Ahoy! Anybody Ahoy!
Please Help me out!
[This message has been edited by Navtaj Singh (edited February 16, 2001).]
[This message has been edited by Navtaj Singh (edited February 16, 2001).]
Matthew Taylor

Joined: Jun 13, 2004
Posts: 110
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.

Grails Consultant
Bob Backlund
Ranch Hand

Joined: Jun 05, 2003
Posts: 51

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

That should sort it.

I agree. Here's the link:
subject: Insertion Of Data
Similar Threads
JDBC and Stored Procedure
Which is best and y
Implementing CASCADE DELETE using Java
xml is for describing data
How to submit a null in radio button