标签:nts logs ddb ++ select .sql except etc code
package com.cme.core; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import com.cme.utils.JdbcUtils; public class Import { public static void main(String[] args) { Connection conn = null; Statement ps = null; Statement ps2 = null; String sql = "select id from pf_enterprise_info2"; try { // 2.建立连接 conn = JdbcUtils.getConnection(); conn.setAutoCommit(false); ps = conn.createStatement(); ps2 = conn.createStatement(); ResultSet rs = ps.executeQuery(sql); int i = 0; while (rs.next()) { // 指针向下移动 String id = rs.getString(1); i++; String sql2 ="update pf_enterprise_info2 set enterprise_import_code=CONCAT(industry_code,‘-RE01-134-‘,LPAD(LEFT(IFNULL(enterprise_import_code,0),8)+"+i+",8,‘0‘)) where id=‘"+id+"‘;"; String sql3 ="update pf_enterprise_info2 set enterprise_code=CONCAT(industry_code,‘-1-‘,LPAD(LEFT(IFNULL(enterprise_import_code,0),8)+"+i+",8,‘0‘)) where id=‘"+id+"‘;"; ps2.addBatch(sql2); ps2.addBatch(sql3); } rs.close(); ps.close(); ps2.executeBatch(); ps2.clearBatch(); conn.commit(); } catch (Exception e) { JdbcUtils.rollback(conn); e.printStackTrace(); } finally { JdbcUtils.free(null, ps, conn); } } }
标签:nts logs ddb ++ select .sql except etc code
原文地址:http://www.cnblogs.com/yueyuepeng/p/6928585.html