Actually I am just trying to insert string something like this 30/01/2012 into a table where that particular table column is of type varchar. After insertion this value is changed into 0.008946322067594433. What may be the reason for this behaviour? Please let me know what I am doing wrong here. I am very poor in database/SQL concepts.
Share
I suspect your SQL looks something like:
in which case it’s not treating it as a string, but an expression to evaluate – which is then being converted into a string. If this is the case, it sounds like you’re building up your SQL string including the value, e.g.
Don’t do that. Use a
PreparedStatementand set parameter values instead. Not only will it avoid this problem, it will also avoid SQL injection attacks, conversion problems with dates and times, etc.(Speaking of which, assuming this value is meant to be a date, why are you storing it in a varchar column? If you possibly can, make your columns represent the data you wish to store more naturally…)
EDIT: I’ve just downloaded and installed MySQL to test this… and indeed in a table with a single column (
Name) this SQL statement does the wrong thing (in MySQL Workbench):… but this does the right thing:
But you should still use a prepared statement with parameters, of course.