Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple mdb connection Error

 
Eric Belec
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason, I can connect to but can't do the "INSERT INTO" statement on my database. The simple mdb file is here .. anyone, if there's an obvious reason why I can't insert data, and you could explain it to me...it would greatly be appreciated. It actually only has 3 entries in it... Its really weird because every other database, I can connect to. But I'm new to Databases so I might be overlooking something simple. Its just a Microsoft access Database .. nothing too complicated

Below the main part of code I use to connect to the database.


Any insight my problem would be appreciated.

[ November 29, 2007: Message edited by: Eric Belec ]
[ November 29, 2007: Message edited by: Eric Belec ]
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the exception stack trace?

Also make sure the MDB file is not read-only.
 
Eric Belec
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the following error



WITH the following code



[ November 30, 2007: Message edited by: Eric Belec ]
[ November 30, 2007: Message edited by: Eric Belec ]
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Eric,

Your code just looks too complicated:



try: just one String, and put a space after PizzaOrder



Herman
PS if you use a preparedstatement, you won't even need the quotes anymore.
 
Eric Belec
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried,



and I'm still getting the "INSERT INTO" error.

just so you know PizzaOrder is a table and the primary key is "Order" which holds a string.

So doesn't this mean there's a problem with the database? As opposed to my code?
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Eric,

Sorry I did not work out (yet).

I Googled some,
maybe Access just does not like the name of this column: "Order".


Herman
 
Eric Belec
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, apparently it didn't like "Order" so I changed that to "Orders" in the database.

Thanks again.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Order is a reserved word in SQL, just like Select and From to name just a few.

You still can use these as names for tables and columns, if you surround them with the table/column name escape characters. In Access and SQL, that is [ and ], so it would be "INSERT INTO PizzaOrder ([Order]) VALUES('5')".
For some other database types it might be ` and `.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
You still can use these as names for tables and columns, if you surround them with the table/column name escape characters.

Of course you want to avoid this if possible since it makes the code harder to maintain. I'm sure Rob is just mentioning it to be thorough, not as advice.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct. The only reserved word I use as column name myself is "name", and that one is only a reserved word in MS SQL Server (well, Query Analyzer marks it in blue ;)).

Unfortunately, sometimes other manufacturers are not as wise. I once had problems installing a package on a MS SQL Server 2005 server. The problem was that one of the column names was a reserved word. We had to enable using reserved words as columns and turn the database compliancy to SQL Server 2000 for it to work. Bloody morons.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic