• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert for mysql

 
Jeremiah Hoyle
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I know I have a ton to learn with java, I have been doing a homework assignment and for over a week now I have been trying to figure out how to get the insert to work for my assignment with no luck. Here is the code I am hoping someone has some pointers for me.



I keep getting the error code when I run it and I have triple checked my database connection and I cannot find a problem there.
 
Paul Clapham
Sheriff
Posts: 21000
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, first of all you have no idea what caused your error, because you put in some code which ignores all the information which is built into the Exception and simply says "There was an error".
So start by replacing that by something like



I'm willing to bet that the actual problem is that you have fouled up your INSERT statement in some way, but it's impossible to tell how from your code. It's just a thicket of SQL quotes and Java string quotes which are easy to get wrong. I strongly suggest you check out PreparedStatement as a way to simplify that code. Of course it also might be something else like "level" being a reserved word, but once you fix your error reporting you should see a proper error message describing your problem.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you have done as @paul suggests, and have it working, make sure you try
entering names such as O'Hara

Hint: your current code will blow up with ugly errors on a lot of Irish and Italian names.
 
Rumesh Eranga
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try executeUpdate() method...

It is better if you can post the error that you getting mate..
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rumesh Eranga wrote:try executeUpdate() method...

Why do you suggest that change? I do not believe it will impact the OP's problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic