• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Java SQL exception non-numeric value appeared where numeric expected

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi my first language is German so bear with my English
i am new to programming and i have form which display Employee tables values in the text field from database. it has a colum date of birth of type Date.
When load program form display all values successfully in the textfield now i have made function update using update query . all other values updated successfully but date objects arent updated when i try to update date objects from the text field and hit save button it give" exception java sql Exception non numeric value appeared where numeric expected" message i do not know how to handle it
i get the date value from textfield from employee form and set this value to employees class

here is the code from employee form

then i have made the update_employee function code is this



how to update date of birth? kindly help please
 
Sheriff
Posts: 28411
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest you rewrite your code to use a PreparedStatement. Using a PreparedStatement means that you don't have to deal with formatting dates in whatever way the database's version of SQL wants to see them. It also takes care of other things which could cause problems, like quote characters in your text fields (the "O'Brien Problem") and guards against SQL injection attacks (where users can put in carefully chosen text which changes your ordinary SQL command to do bad things to your database).

You'll find a tutorial about PreparedStatement here: http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html
 
Ranch Hand
Posts: 50
5
Oracle Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While I agree with Paul, of course...

Paul Clapham wrote:I would suggest you rewrite your code to use a PreparedStatement. [...]



... your current problem can be solved by writing



The above date literal syntax is specified by the SQL standard. It accepts the following format: DATE 'YYYY-MM-DD', which is what happens to be produced by java.sql.Date.toString().

In case you're using the Derby database, use this instead:



In case you're using a T-SQL database (SQL Server, Sybase ASE, Sybase SQL Anywhere) or SQLite, just use the plain date string as such:



But again, it would really be better to follow Paul's advice and use a PreparedStatement with bind values instead.
reply
    Bookmark Topic Watch Topic
  • New Topic