2016-12-29 45 views
0

我在Windows 7中使用MS Access數據庫創建Java應用程序。當我執行select查詢時,一切都很好。但是,當我從Java應用程序更新MS Access數據庫的DATE字段時,它會引發SQL異常。以下是我的MS Access表結構和Java代碼。提前致謝。使用Java在MS Access中更新日期字段

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

我的Java源代碼是在這裏:

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(); 
      } 

我得到這個錯誤在日誌中:

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) 

回答

0

使用ISO序列(YYYY-MM-DD),敷在爲獲得日期值的適當字符串表達式,使用十進制表示法:

ps1.setString(1, "#2016/12/29#"); 
相關問題