解析错误如果我将数据保存到MSAccess 2000 [英] Got Parsing Error If I am saving data to MSAccess 2000

查看:72
本文介绍了解析错误如果我将数据保存到MSAccess 2000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面提到的代码在MSAccess 2000中插入值,其中包含如下所述的表结构: -



字段名称数据类型

TodaysDate日期/时间

购物车识别号码

客户名称文字

团队&细分文字

持续时间编号

磁带ID文字

开始日期日期/时间

结束日期日期/时间< br $>




代码: -





I am using below mentioned code to insert values in MSAccess 2000 which having table structure as mentioned below:-

Field Name Data Type
TodaysDate Date/Time
Cart ID Number
Client Name Text
Team & Segment Text
Duration Number
Tape ID Text
Start Date Date/Time
End Date Date/Time


Code:-


private boolean enterDataIntoMSAccessDatabaseusingPreparedStatement()
    {
        try {

            ps = connection.prepareStatement("INSERT INTO Cart ID Details VALUES (?,?,?,?,?,?,?)");

            System.out.println("After Query");

        }

        catch (SQLException se) {

            generateErrorMessage("Error in Prepared Statement \n " + se.getMessage() );

            return false;

        }

        catch (Exception e)
        {
            generateErrorMessage("Unexpected Error Occured \n " + e.getMessage());
        }

        String todaysDate = cartIDApplicationAddCartIDDatejTextField.getText().trim();

        String cartID = cartIDApplicationAddCartIDCartIDjTextField.getText().trim();

        String clientName = cartIDApplicationAddCartIDClientNamejTextField.getText().trim();

        String teamSegment = cartIDApplicationAddCartIDTeamAndSegmentjTextField.getText().trim();

        String duration = cartIDApplicationAddCartIDDurationjTextField.getText().trim();

        String tapeID = cartIDApplicationAddCartIDTapeIDjTextField.getText().trim();

        String startDate = cartIDApplicationAddCartIDStartDatejTextField.getText().trim();

        String endDate = cartIDApplicationAddCartIDEndDatejTextField.getText().trim();

        try {

            System.out.println("Before ps.setString()");

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd", Locale.ENGLISH);
            System.out.println("Simple Date Format");

            /*ps.setString(1, todaysDate);
            ps.setString(2, cartID );
            ps.setString(3, clientName);
            ps.setString(4, teamSegment);
            ps.setString(5, duration);
            ps.setString(6, tapeID);
            ps.setString(7, startDate);
            ps.setString(8, endDate);*/

            ps.setDate(1, new java.sql.Date(simpleDateFormat.parse(todaysDate).getTime()));
            ps.setString(2, cartID);
            ps.setString(3, clientName);
            ps.setString(4, teamSegment);
            ps.setString(5, duration);
            ps.setString(6, tapeID);
            ps.setDate(7, new java.sql.Date(simpleDateFormat.parse(startDate).getTime()));
            ps.setDate(8, new java.sql.Date(simpleDateFormat.parse(endDate).getTime()));

            System.out.println("After ps.setString()");

            ps.executeUpdate();


       }
        catch (SQLException se) {

            generateErrorMessage("Error while inserting data in database \n " + se.getMessage());

            return false;
        }

        catch (Exception e)
        {
            generateErrorMessage("Unexpected Error Occured \n" + e.getMessage() );
        }

        return true;
    }










I got below error after implementing the above code:-

Unexpected Error Occured
Unparseable date: "11-Nov-2013"

Kindly help me for the same.

推荐答案

如果您想确定日期,请务必转换它们到年月日,因为这是唯一的通用格式。从第一年开始,始终是月份,日期将是最后一个。并且不要使用11月或11月,因为它非常特定于语言,并且ms-office对此非常敏感。只要确保它会一直成功,不用担心区域设置或任何事情,日期就像是:2013-11-11

顺便说一句,excel也一样。



祝你好运!
If you want to be sure with dates, always convert them to year-month-day because that is the only universal format. When starting with the year first, the month always follows and the date will be last. And don't use Nov or November because it is very language specific and ms-office is extremely sensitive on that. Just make sure it will always succeed, without worrying about regional settings or anything, the date is like : 2013-11-11
The same goes for excel by the way.

Good luck!


这篇关于解析错误如果我将数据保存到MSAccess 2000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆