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

servlets and sql

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.... ??
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regardless of the types, use a PreparedStatement as Paul suggested. It'll make your life so much easier.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic