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 servlets and sql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "servlets and sql" Watch "servlets and sql" New topic

servlets and sql

Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
ok peoples,

I have a problem. I'm in the process of creating a online system where people login and stuff. I've got the login page working correctly and the database connection working correctly also. I have given users the option to register if they have not been on before, and this is where I come unstuck. The user enters in their details (into a jsp page this is), and clicks the register button and it attempts to enter the new record into the database.
Every field they have to enter is either a text field or a drop down box. Their date of birth is entered via 3 drop down boxes. One for day, one for month and one for year.
Once the register button is clicked, it uses a servlet to check the database and enter the record.

That is some of the code from the servlet. The error that I get is below.

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression '''October 27 1988'''.

I think this is an SQL error, to do with the way the user enters the date but i'm not sure.
Can anyone help me?

[ September 17, 2004: Message edited by: Bear Bibeault ]
Jyothi Lature
Ranch Hand

Joined: Oct 31, 2001
Posts: 60

Check the format of the date field and insert the DOB value in the same format. You can change format of the Date variable using SimpleDateFormat class in java.

Jyothi<br />Sun Certified Java Programmer<br />Brainbench Certified for Javascript
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Alternatively use a PreparedStatement and bind the date parameter as a java.sql.Date object rather than a String. Much safer, and means you can swap the database (or change the date format - if you were using a better database than Access) without having to change your SimpleDateFormat.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
the DOB is a string in the database as well (or text as Access calls it), which is why I am a little confused because I thought just about any symbol/combination of symbols could go into that.... ??
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63540

Regardless of the types, use a PreparedStatement as Paul suggested. It'll make your life so much easier.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: servlets and sql
jQuery in Action, 3rd edition