I want to insert "0001-01-01" as the value in the date field using Java PreparedStatement .
But this throws an exception when I tried this:
String sql = "insert into mytable values(?)" ps = conn.prepareStatement(sql); ps.setDate(1, java.sql.Date.valueOf("0001-01-01")); ps.executeUpdate();
Error:
The value shown is not a valid instance of the datetime data type. Check the source data for invalid values. An example of an invalid value is numeric data with a scale that exceeds accuracy.
If I do not use PreparedStatement, I can insert "0001-01-01". However, make does not seem to allow me to insert this value.
It will work if I inserted "1969-01-01" instead of "0001-01-01."
Any ideas?
Updates: Here is more information you may need.
- we are using SQL Server 2012.
- we must use "0001-01-01" because these values ββalready existed. I use very old codes to use the preparation instructions. Therefore, I need to insert the same values ββinto the same functionality.
Updates 2:
In addition, I can insert β0001-01-01β into the date field without using the preparation instructions. i.e.
String sql = "insert into mytable values('0001-01-01')" java.sql.Statement statement = conn.createStatement(); statement.executeUpdate(sql);
So this is not sql server problem or db field problem.
source share