aspose file tools*
The moose likes JDBC and the fly likes general SQL error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "general SQL error?" Watch "general SQL error?" New topic
Author

general SQL error?

Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
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...

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18903
    
    8

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

Joined: Sep 19, 2003
Posts: 133
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
Bartender

Joined: Oct 14, 2005
Posts: 18903
    
    8

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

Joined: Sep 19, 2003
Posts: 133
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?
Martin Simons
Ranch Hand

Joined: Mar 02, 2006
Posts: 196
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

Joined: Sep 19, 2003
Posts: 133
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: general SQL error?