SQL Insert - which method to use

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2008
Posts: 42
Reputation: marcosjp is an unknown quantity at this point 
Solved Threads: 0
marcosjp marcosjp is offline Offline
Light Poster

SQL Insert - which method to use

 
0
  #1
Jun 5th, 2008
Hi there!

I'm building a small application using Java and MySQL (college assignment).
Everything is ok when all I'm doing are queries using SELECT.
Now, when I try to INSERT anything in the table, I get this error message:

java.sql.SQLException: Can not issue data manipulation statements with executeQuery(). 0 S1009

Ok, so I should use something else other than executeQuery to manipulate data (and I suppose the same will happen if I try to UPDATE the table as well).

So, please, what should I use? I tried other methods from NetBeans but did not quite understand how to use them.

This is the code I'm using:

  1. Statement statement=conn.createStatement();
  2. ResultSet resultSet=statement.executeQuery(sqlstring);

Thanks!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,391
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 254
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: SQL Insert - which method to use

 
0
  #2
Jun 6th, 2008
executeUpdate not executeQuery (on non-select queries)
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC