Java.sql。sqlexception:将char数据类型转换为datetime数据类型会导致一个超出范围的datetime值

时间:2022-07-31 16:43:55

When I am updating my Date Field the update does not works from NetBeans and Below exception is raised

当我更新我的日期字段时,更新不能从NetBeans中工作,并引发以下异常

Java.sql.sqlexception: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value

Java.sql。sqlexception:将char数据类型转换为datetime数据类型会导致一个超出范围的datetime值

However I run the same query the query works fine in SQL Query Analyzer (SQL Server 2000)

然而,我在SQL query Analyzer (SQL Server 2000)中运行查询工作良好的查询

I am formatting the Date Value to be updated as follows in NetBeans.

我正在格式化要在NetBeans中更新的日期值。

        JXDatePicker jDatePicker = (JXDatePicker) comp;
        Date date = jDatePicker.getDate();
        if (date != null) {
        try {
            String expectedPattern = "yyyy-MM-dd HH:mm:ss.SSS";
            String currentFormat = "dd-MM-yyyy HH:mm:ss.SSS";

            SimpleDateFormat dateFormatReq = new SimpleDateFormat(expectedPattern);

            SimpleDateFormat dateFormatCurr = new SimpleDateFormat(currentFormat);          

            // To Convert Date To Required Format For DB

            //First Prepare A String In Current Format dd-MM-yyyy
            // Then Convert To The Date In The Current Format dd-MM-yyyy
            // Then Convert Into  String In The Desired Format yyyy-MM-dd
            String strDate =     dateFormatReq.format(dateFormatCurr.parse(dateFormatCurr.format(date)));

        } catch (ParseException ex) {
        Logger.getLogger(ChangeJControlProperties.class.getName()).log(Level.SEVERE, null, ex);
        }

        } 

String query =update myTable
               set date=strDate  where id=myDd

For Date 2013-07-05 it updates successfully.

为日期2013年7月5日成功更新。

For Date 2013-06-28 it displays the above exception

对于日期2013-06-28,它显示了上面的异常

1 个解决方案

#1


0  

The problem has been solved as the Default Language Selected was Thai, when i change it to English the exception does not come and the problem disappears.

问题已经解决了,因为选择的默认语言是泰语,当我将它改为英语时,异常不会出现,问题就消失了。

#1


0  

The problem has been solved as the Default Language Selected was Thai, when i change it to English the exception does not come and the problem disappears.

问题已经解决了,因为选择的默认语言是泰语,当我将它改为英语时,异常不会出现,问题就消失了。