Java – how to fix errors when inserting datetime into DB

I want to do this:

pr.setStartdate("2006-09-10T00:00:00");

I received this error:

java.sql.sqlDataException: The Syntax of the string representation of a datetime value is incorrect.

Any idea of how to successfully insert will be great

Here are some codes Do I need setDate now? Or is setstring applicable to begintime, Endtime and date? They are datetime objects:

PreparedStatement pstmt = conn.prepareStatement("UPDATE Event SET date=?,begintime=?,endtime=?,status=?,productionid=?,conceptual_packageid=? WHERE id=?");
        pstmt.setString(1,pkg.getDate());
        pstmt.setString(2,pkg.getBeginTime());
        pstmt.setString(3,pkg.getEndTime());
        pstmt.setString(4,pkg.getStatus());
        pstmt.setString(5,pkg.getProductionID());
        pstmt.setString(6,pkg.getConceptual_PackageID());
        pstmt.setString(7,pkg.getId());

        pstmt.executeUpdate();
        pstmt.close();

Solution

I recommend that you use the settimestamp (...) and setDate (...) methods of Preparedstatement and then pass the actual date object to them instead of using a string If you can only use strings in the "PR" class, convert the string to the format specified in Derby doc, and then use the following code

java.sql.Timestamp.valueOf("time/date converted");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>