• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Simple mdb connection Error

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 22806
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22806
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 `.
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22806
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic