wood burning stoves 2.0*
The moose likes JDBC and the fly likes Insert for mysql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Insert for mysql" Watch "Insert for mysql" New topic
Author

Insert for mysql

Jeremiah Hoyle
Greenhorn

Joined: Feb 01, 2012
Posts: 4
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Aug 11, 2007
Posts: 4646
    
    5

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

Joined: Jan 26, 2011
Posts: 34
try executeUpdate() method...

It is better if you can post the error that you getting mate..
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Rumesh Eranga wrote:try executeUpdate() method...

Why do you suggest that change? I do not believe it will impact the OP's problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Insert for mysql
 
Similar Threads
Problems w/ a HashMap
Problem Using PrintWriter class !
inheritance homework assignment - im stuck
SQL formatting question
getting java.lang.NoSuchMethodError: main error! thanks =)