Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes Simple mdb connection Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Simple mdb connection Error" Watch "Simple mdb connection Error" New topic
Author

Simple mdb connection Error

Eric Belec
Greenhorn

Joined: Nov 29, 2007
Posts: 12
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

Joined: Oct 27, 2005
Posts: 19542
    
  16

Can you post the exception stack trace?

Also make sure the MDB file is not read-only.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Eric Belec
Greenhorn

Joined: Nov 29, 2007
Posts: 12
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

Joined: Jul 17, 2006
Posts: 387
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

Joined: Nov 29, 2007
Posts: 12
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

Joined: Jul 17, 2006
Posts: 387
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

Joined: Nov 29, 2007
Posts: 12
Thank you, apparently it didn't like "Order" so I changed that to "Orders" in the database.

Thanks again.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19542
    
  16

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29237
    
139

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19542
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple mdb connection Error
 
Similar Threads
WSAD: SQL queries in Data Perspective
Need help with a SQL statement
problem while accessing class file from a package
Java SQL Exception General Error
using data base Access