java - mysql executeBatch批量提交数据,varchar字段内容带(")双引号
PHP中文网
PHP中文网 2017-04-18 10:17:21
0
2
751

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

处理代码:

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本身是不带有""的!

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
黄舟

No one paid attention, so in the end I had to use the stupidest method, replace()...

阿神

Isn’t it because your string itself contains ""?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template