File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

general SQL error?

 
Brandi Love
Ranch Hand
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • 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...

 
Paul Clapham
Sheriff
Pie
Posts: 20191
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Pie
Posts: 20191
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Martin Simons
Ranch Hand
Posts: 196
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic