简体   繁体   中英

Update Date Field in MS Access Using Java

I am creating a Java application with MS Access Database in Windows 7. Everything is fine when I am doing the select query. However, when I UPDATE the DATE field of the MS Access DB from the Java application, it throws a SQL Exception. Below is my MS Access table structure and Java code. Thanks in advance.

[![This is my Ms Access Table date field structure][1]][1]

My java source code is here:

String qry1="SELECT Isometric_number FROM Tbl_Weld_Details WHERE Line_number='0470-52-ADB-17034001-01' AND Sheet_number='1/2'";
            try{
                Connection con=Database.Get_Connection();
                PreparedStatement ps = con.prepareStatement(qry1);
                ResultSet rs = ps.executeQuery();
                if(rs.next())
                {
                    String Iso_no = rs.getString(1);                        

                    String qry2="UPDATE Tbl_Weld_Register SET Weld_date=?,Welders_Root1=?,Welders_Cap1=? WHERE Isometric_number=? AND Spool_No=? AND Weld_number=?";

                    PreparedStatement ps1 = con.prepareStatement(qry2);                     

                    ps1.setString(1, "29/12/2016");  //Problem is here
                    ps1.setString(2, "Cheliyan");
                    ps1.setString(3, "Raja");
                    ps1.setString(4, Iso_no);
                    ps1.setString(5, "SPL-1");
                    ps1.setString(6, "1");
                    System.out.print("Query2===========>"+qry2);
                    int res1=ps1.executeUpdate();                       

                    if(res1 > 0)
                    {
                        isSuccess = true;
                    }

                }

            }
            catch (Exception e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

I get this error in the logs:

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 
ERROR DATE: Kindly check Weld Date or NDE Date...

at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source)
at dao.EmployeeTmsDao.updateJointNoStatus(EmployeeTmsDao.java:76)

使用ISO序列(yyyy-mm-dd)并包装八叉索以获得正确的字符串表达式作为日期值:

ps1.setString(1, "#2016/12/29#"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM