Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Insert for mysql

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 26973
85
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4686
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic