• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java and MySQL

 
Jil Van Wetter
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Here is my problem:

I don't have a lot of experience with Java (I am using Eclipse if that's relevant) in general and certainly not when I try to combine it with MySQL.
I am trying to learn to import, export and modify data that can be found in the database.
I have read a lot of tutorials online and based on these tutorials I have written a code.
The first part, printing the data that is stored in the database works just fine, but when I try to add some data, I get an error.

This is the code I used:



This is the output I get (as you can see, printing the data works fine):

1 - Bart - man
2 - Catherine - vrouw
3 - Walter - man
4 - Danny - man
5 - Claude - man
6 - Roger - man

Exception in thread "main" java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.Statement.checkForDml(Statement.java:417)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1383)
at TestDB.main(TestDB.java:32)


Can somebody help me?
Thanks in advance!
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the Javadocs for java.sql.PreparedStatement, you'll see that there are two execution statements. executeQuery() is used to run queries, and returns a ResultSet. For your update you need the other one - executeUpdate().
 
Jil Van Wetter
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:If you look at the Javadocs for java.sql.PreparedStatement, you'll see that there are two execution statements. executeQuery() is used to run queries, and returns a ResultSet. For your update you need the other one - executeUpdate().


Thanks! It solved my problem!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic