File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes JDBC insert record Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC insert record" Watch "JDBC insert record" New topic

JDBC insert record

Minh Phan

Joined: Sep 23, 2004
Posts: 8
After connecting the Access database, try to insert a record and an error message is displayed: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Invalid attribute/option identifier. Why use the commented out lines it is OK? Please help. Here is the code:

[edited to disable smilies and add code tags]
[ October 05, 2004: Message edited by: Jeanne Boyarsky ]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33122

Welcome to JavaRanch!

I suggest using a prepared statement instead of a statement. That takes care of the formatting for you.

Check whether the table is defined using the columns in the same order as are in your SQL insert. Or better yet, add the column names explicitly to the SQL.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Hi Minh

Welcome to Javaranch. Sure you will have a great time Ranching here

I suggest using a prepared statement instead of a statement

I too second the strong recommendation of prepared statement.

It is compiled once and then can be reused. When u want to add some performance measures to your code, you go for the PreparedStatement. You have quite a good time...using that.

Simple and effecient enough.

And did u try the query at the DB console? Did it work properly?Try this out and if trouble still persists, you know where to get back.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: JDBC insert record
It's not a secret anymore!