Excel导入Oracle数据中表日期变成五位数字,怎样去修改

时间:2024-03-11 08:25:46
    @Test
    public void test() throws Exception{
        //DbAccess封装数据库的连接配置
        DbAccess db=new DbAccess();
        Connection conn=db.getConnection();
        Statement st=conn.createStatement();
        ResultSet rs=null;
        try {
            //获取要修改的日期字段和主键标识字段
            List<List<String>> list=new ArrayList<List<String>>();
            String sql="select ACCT_NO,BAD_DEBT_TRF_DTE from kim_f_borm_base_hz  where subj_no like \'713%\'";
            rs=st.executeQuery(sql);
            while(rs.next()){
            List<String> list2=new ArrayList<String>();
            String acct_no=rs.getString("ACCT_NO");
            String bad=rs.getString("BAD_DEBT_TRF_DTE");
            list2.add(acct_no);
            list2.add(bad);
            //添加到list集合中
            list.add(list2);
            }
            //进行for循环遍历修改
            System.out.println(list.size());
            for (int i = 0; i < list.size(); i++) {
                List<String> list3= list.get(i);
                for (int j = 0; j < list3.size(); j++) {
                    String bad=list3.get(1);
                    int num=Integer.valueOf(bad);
                    Calendar calendar=new GregorianCalendar(1900,0,-1);
                    calendar.add(Calendar.DAY_OF_MONTH, num);
                    SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
                    System.out.println(sdf.format(calendar.getTime()));
                    String bad1=sdf.format(calendar.getTime());
                    String sql1="update kim_f_borm_base_hz set BAD_DEBT_TRF_DTE=\'"+bad1+"\' where ACCT_NO=\'"+list3.get(0)+"\'";
                    System.out.println(sql1);
                    st.executeUpdate(sql1);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }