java.sql.SQLException:数据截断JSP和Struts1

时间:2017-11-20 05:59:01

标签: java mysql sqlexception struts1

我在JSP页面上使用用户输入将数据插入到大约20个MySQL数据库表中。有些表插入了四行数据。

我收到“java.sql.SQLException:数据截断列”,即使数据不长于相应列中允许的数据。例如,将整数9插入整数列中。

从我的代码中摘录:

    String sql = "insert into BO_Server_Details values (?,?,?,?,?,?,?)";
         PreparedStatement ps = conn.prepareStatement(sql);
         //Coding for date values 
//         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date1);
//         java.sql.Date sqlDate = new java.sql.Date(date1.getTime());
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setString(3, Server_Model_Config);
         ps.setString(4, Server_SN);
         ps.setString(5, UPS_Supply_Earthing);
         ps.setString(6, Server_Change_Extra_HD);
         ps.setString(7, Last_Change_Date1);
         int i1=ps.executeUpdate();
         System.out.println("Record inserted successfully");

         sql = "insert into BO_Server_DateTime values (?,?,?,?,?)";
//         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date2);
//         sqlDate = new java.sql.Date(date1.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3,1);
         ps.setString(4, DTTM2);
         ps.setString(5, Last_Change_Date2);
         int i2=ps.executeUpdate();

         //System.out.println("Record inserted successfully");

         sql = "insert into BO_Server_DateTime values (?,?,?,?,?)";
//         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date3);
//         sqlDate = new java.sql.Date(date1.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3,2);
         ps.setString(4, DTTM3);
         ps.setString(5, Last_Change_Date3);
         int i3=ps.executeUpdate();


         sql = "insert into BO_Server_DateTime values (?,?,?,?,?)";
//         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date4);
//         sqlDate = new java.sql.Date(date1.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3,3);
         ps.setString(4, DTTM4);
         ps.setString(5, Last_Change_Date4);
         int i4=ps.executeUpdate();

//
         sql = "insert into BO_Server_DateTime values (?,?,?,?,?)";
//         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date5);
//         sqlDate = new java.sql.Date(date1.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3,4);
         ps.setString(4, DTTM5);
         ps.setString(5, Last_Change_Date5);
         int i5=ps.executeUpdate();

//
//                  
         sql = "insert into BO_Server_AMC values (?,?,?,?,?)";
////         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date54);
////         sqlDate = new java.sql.Date(date1.getTime());
////         date2 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Qly_PM_Date);
////         java.sql.Date sqlDate2 = new java.sql.Date(date2.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setString(3, PM_Done_Or_Not);
         ps.setString(4, Qly_PM_Date);
         ps.setString(5, Last_Change_Date54);
         int i6 = ps.executeUpdate();
////         
         sql = "insert into BO_HD_Usage values (?,?,?,?,?)";
////         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date6);
////         sqlDate = new java.sql.Date(date1.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3, dbData);
         ps.setInt(4, ImageData);
         ps.setString(5, Last_Change_Date6);
         int i7 = ps.executeUpdate();
////         
         sql = "insert into BO_HotFix_Version values (?,?,?,?,?)";
////         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date7);
////         sqlDate = new java.sql.Date(date1.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3, 1);
         ps.setInt(4, Version_No1);
         ps.setString(5, Last_Change_Date7);
         int i8 = ps.executeUpdate();
////         
         sql = "insert into BO_HotFix_Version values (?,?,?,?,?)";
////         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date8);
////         sqlDate = new java.sql.Date(date1.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3, 2);
         ps.setInt(4, Version_No2);
         ps.setString(5, Last_Change_Date8);
         int i9 = ps.executeUpdate();
////         
         sql = "insert into BO_HotFix_Version values (?,?,?,?,?)";
////         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date9);
////         sqlDate = new java.sql.Date(date1.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3, 3);
         ps.setInt(4, Version_No3);
         ps.setString(5, Last_Change_Date9);
         int i10 = ps.executeUpdate();
////         
         sql = "insert into BO_HotFix_Version values (?,?,?,?,?)";
////         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date10);
////         sqlDate = new java.sql.Date(date1.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3, 4);
         ps.setInt(4, Version_No4);
         ps.setString(5, Last_Change_Date10);
         int i11 = ps.executeUpdate();
////         

         sql = "insert into BO_Pending_Records values (?,?,?,?,?,?,?,?)";
////         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date11);
////         sqlDate = new java.sql.Date(date1.getTime());
////         date2 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",eFeap_Error_Log_Attended1);
////         sqlDate2 = new java.sql.Date(date2.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3, 1);
         System.out.println("Synch_Records_Pending1:" +Synch_Records_Pending1);
         ps.setInt(4, Synch_Records_Pending1);
         ps.setInt(5, Transfer_Records_Pending1);
         ps.setInt(6, PNF_Records_Pending1);
         ps.setString(7, eFeap_Error_Log_Attended1);
         ps.setString(8, Last_Change_Date11);
         int i12 = ps.executeUpdate();

////         
         sql = "insert into BO_Pending_Records values (?,?,?,?,?,?,?,?)";
////         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date12);
////         sqlDate = new java.sql.Date(date1.getTime());
////         date2 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",eFeap_Error_Log_Attended2);
////         sqlDate2 = new java.sql.Date(date2.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3, 2);
         System.out.println("Synch_Records_Pending2:" +Synch_Records_Pending2);
         ps.setInt(4, Synch_Records_Pending2);
         ps.setInt(5, Transfer_Records_Pending2);
         ps.setInt(6, PNF_Records_Pending2);
         ps.setString(7, eFeap_Error_Log_Attended2);
         ps.setString(8, Last_Change_Date12);
         int i13 = ps.executeUpdate();
////         
         sql = "insert into BO_Pending_Records values (?,?,?,?,?,?,?,?)";
////         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date13);
////         sqlDate = new java.sql.Date(date1.getTime());
////         date2 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",eFeap_Error_Log_Attended3);
////         sqlDate2 = new java.sql.Date(date2.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3, 3);
         System.out.println("Synch_Records_Pending3:" +Synch_Records_Pending3);
         ps.setInt(4, Synch_Records_Pending3);
         ps.setInt(5, Transfer_Records_Pending3);
         ps.setInt(6, PNF_Records_Pending3);
         ps.setString(7, eFeap_Error_Log_Attended3);
         ps.setString(8, Last_Change_Date13);
         int i14 = ps.executeUpdate();
////         
         sql = "insert into BO_Pending_Records values (?,?,?,?,?,?,?,?)";
////         date1 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",Last_Change_Date14);
////         sqlDate = new java.sql.Date(date1.getTime());
////         date2 = Utilities.formatToDate("yyyy-MM-dd","yyyy-MM-dd",eFeap_Error_Log_Attended4);
////         sqlDate2 = new java.sql.Date(date2.getTime());
         ps = conn.prepareStatement(sql);
         ps.setString(1, BO_Code);
         ps.setString(2, MMYY);
         ps.setInt(3, 4);
         System.out.println("Synch_Records_Pending4:" +Synch_Records_Pending4);
         ps.setInt(4, Synch_Records_Pending4);
         ps.setInt(5, Transfer_Records_Pending4);
         ps.setInt(6, PNF_Records_Pending4);
         ps.setString(7, eFeap_Error_Log_Attended4);
         ps.setString(8, Last_Change_Date14);
         int i15 = ps.executeUpdate();


         conn.close();

0 个答案:

没有答案