• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlets and sql

 
Bron Czimes
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Bron
[ September 17, 2004: Message edited by: Bear Bibeault ]
 
Jyothi Lature
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bron Czimes
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regardless of the types, use a PreparedStatement as Paul suggested. It'll make your life so much easier.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic