permaculture playing cards
The moose likes JDBC and Relational Databases and the fly likes count field incorrect error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "count field incorrect error" Watch "count field incorrect error" New topic

count field incorrect error

Werner Fletcher
Ranch Hand

Joined: Apr 19, 2011
Posts: 34
I have created an Access database, with a "Users" table with fields: "personname", "surname", "email", "username", "password", "secretQuestion", "answer".
I am getting a count field incorrect error when i process this:

Please tell me if I did something wrong here, because I don't know and I am ready to
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

You did two things wrong, actually.

First, your SQL INSERT statement doesn't use the correct syntax. Look here for a page which describes the correct syntax. (You didn't use parentheses.)

Second, constructing an SQL statement that way is error-prone and risky. For one thing, if any of the string values contain quotes -- and they could -- then the result is not valid SQL. And for another thing, it's possible for evil users to uses that statement for "SQL Injection" attacks; humorous example here.

The cure for both of those problems is to use PreparedStatement; you should find that in any reputable JDBC tutorial.
Werner Fletcher
Ranch Hand

Joined: Apr 19, 2011
Posts: 34
Thanks alot guys, I appreciate the help alot. I am using PreparedStatement now aswell as MySQL server. I was having endless issues with MS Access and Win 7 64-bit aswell. Everything is working 100%.
I agree. Here's the link:
subject: count field incorrect error
It's not a secret anymore!