• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

general SQL error?

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all!

I'm sure I'm being a royal pain in the butt with all of my questions but this project I'm working on is driving me nuts and I've found that this is the best place to come to when I need some help.

So, I've written this code to connect to an access database on my hard drive. I found the code to do this here using the direct connect method. Everything appeared to connect correctly until I added the statement. Now I'm getting the following error when it catches:


It provides no specifics and I'm sure its the statement I'm just not sure what could be wrong with it. Any ideas? Code is below...

 
Marshal
Posts: 28193
95
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
That's your error message that gives no specifics, actually. When an exception is thrown, it's a good idea to print the stack trace. This tells you what class of exception was thrown, and what line of code threw it. Like this:But for now I'm going to guess that the exception occurs when you try to execute the SQL insert statement:Perhaps the employees table doesn't have exactly three columns. Or perhaps not all of them contain string data. Or perhaps the first one only allows strings of three characters or fewer. At any rate something's wrong with it, and you would have to check your table definition to find out just what. That's assuming that my guess was right about what line of code is throwing the exception.
 
Brandi Love
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I double checked my database - all three fields are text. The first is limited to 5 chars, the other two to 50, so my configuration doesn't appear to be the problem as far as I can tell. I did as you said and changed the error to a stack trace, this is the error it shows now:


It is indeed that line but I'm not sure what these errors mean, not to familiar with this stuff.
 
Paul Clapham
Marshal
Posts: 28193
95
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
These two lines of the stack trace:tell you that the exception occurred at line 14 of your TestDB class, in the "main" method, where you were calling the "execute" method. So, it tells you exactly what line threw the exception.

As for why it threw the exception, it's a crummy Access error message. Something's wrong with your query, and that's all it's telling you. Maybe making that insert would result in duplicate keys or something like that. You're going to have to look at your database setup more closely.
 
Brandi Love
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't an issue with this specific table because it doesn't use it - but how does JDBC deal with a field in an access database with an auto increment set on it?
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jdbc doesn't deal with the auto increment at all. It simply gives the sql
statement to the server to execute. So you tell me, how does access deal
with a field with auto increment?
 
Brandi Love
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I presume there is some sort of code deep within the bowels of access that processes the increment. That would be easy enough to write myself in Java.
reply
    Bookmark Topic Watch Topic
  • New Topic