Hi i am trying to execute query
Statement stmt = conn.createStatement();
stmt.executeUpdate(location_query);
location_query is
insert into table(col, col2) value("2", "");
Both col and col2 are double(12,2) type, i get error
Data truncated for column 'col2' at row 1, but if I print my query and copy, and paste it to PMA (PhpMyAdmin) its correct.
I guesst that its becouse value of col2 is empty, but is there chance to solve this in other way not to checking all variables which im trying to put to my query ??
Well, an empty String is not a valid number, therefore different database systems might handle that differently. When you just want that column NULL or filled with the default, you should leave it out like this:
OR set it NULL explicitly:
Besides, numbers are written without quotes in SQL. Furthermore, you should cosider using PreparedStatements only. PreparedStatements give you type saftly and protect from SQL injection and might be faster when reused.
Take a look at google “statement vs. preparedstatement”
EDIT
Your example would look something like this, when using prepared statements: