搜尋

首頁  >  問答  >  主體

mysql executeBatch批量提交数据,varchar字段内容带(")双引号

java利用PreparedStatement批量提交数据后,表中所有的varchar类型字段内容均被加上了双引号,如图:

3819165318-58198e483e730_articlex.png

3626464628-58198e5ab8f1a_articlex.png

处理代码:

sql = "INSERT INTO tbvoscdr VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                            PreparedStatement psts = conn.prepareStatement(sql);
                            //for(int k =0;k<50;k++){
                            while ((strArray = queue.poll()) != null) {
                                Date startTime =  new Date(Long.parseLong(strArray[17]));
                                Date stopTime =  new Date(Long.parseLong(strArray[18]));
                                    psts.setLong(1, Long.valueOf(strArray[36]));
                                    psts.setString(2, String.valueOf(strArray[0]));
                                    psts.setString(3, strArray[1]);
                                    psts.setString(4, strArray[2]);
                                    psts.setString(5, strArray[3]);
                                    psts.setString(6, strArray[4]);
                                    psts.setString(7, strArray[5]);
                                    psts.setString(8, strArray[7]);
                                    psts.setString(9, strArray[9]);
                                    psts.setString(10, strArray[10]);
                                    psts.setString(11, strArray[12]);
                                    psts.setInt(12, Integer.valueOf(strArray[16]));
                                    psts.setString(13, df.format(startTime));
                                    psts.setString(14, df.format(stopTime));
                                    psts.setInt(15, Integer.valueOf(strArray[21]));
                                    psts.setInt(16, Integer.valueOf(strArray[23]));
                                    psts.setDouble(17, Double.valueOf(strArray[24]));
                                    psts.setDouble(18, Double.valueOf(strArray[27]));
                                    psts.setString(19, strArray[28]);
                                    psts.setString(20, strArray[29]);
                                    psts.setDouble(21, Double.valueOf(strArray[31]));                                                                
                                    psts.setString(22, strArray[34]);
                                    psts.setString(23, strArray[35]);
                                    psts.setString(24, strArray[37]+","+strArray[38]);
                                    psts.setInt(25, Integer.valueOf(strArray[39]));
                                    psts.setString(26, strArray[40]);
                                    psts.setString(27, strArray[41]);
                                    psts.setInt(28, Integer.valueOf(strArray[42]));
                                    psts.setInt(29, Integer.valueOf(strArray[43]));
                                    
                                    psts.addBatch();  
                                    }
                            //}
                            if(count != 0){
                                psts.executeBatch(); // 执行批量处理
                                conn.commit();  // 提交
                                //System.out.println(""+count);                                
                            }

尝试了很久没办法将字符串“”去除,希望各路神仙指点一二,谢谢!

String text = new String(dp.getData(),0,dp.getLength());//DatagramPacket包
String[] strArray = null;
strArray = text.split(",");

被处理的strArray本身是不带有""的!

高洛峰高洛峰2939 天前848

全部回覆(2)我來回復

  • 欧阳克

    欧阳克2016-11-12 14:04:00

    用最笨的办法,replace()...

    回覆
    0
  • 三叔

    三叔2016-11-12 14:03:47

    不是因为你的字符串中本身就带有""吗?

    回覆
    0
  • 取消回覆