• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java SQL exception non-numeric value appeared where numeric expected

 
Azeem Rathore
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
 
Lukas Eder
Ranch Hand
Posts: 49
5
Java Oracle Postgres Database
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic