用程序实现SQL的表导出

while(rs.next()){ ++queryCount; for(int i=1;i<=count;i++){destPs.setObject(i, rs.getObject(i)); } destPs.setObject(count+1, rs.getObject(pk)); destPs.addBatch(); if(batchSize%100==0){destPs.executeBatch(); }}destPs.executeBatch();

/* * 生成插入语句 * @param tag 对于设置了主键自动增长的表,,需要 * set identity_insert “+tableName+” ON * */public String sqlGenerate(int count,ResultSetMetaData rsd,String tableName,String pk,boolean tag) throws SQLException{String sql=””;if(tag){sql=”set identity_insert “+tableName+” ON;”;}sql+=” insert into “+tableName;//columnssql+=”(“+rsd.getColumnName(1);for(int i=2;i<=count;i++){sql+=’,’;sql+=rsd.getColumnName(i);}sql+=”)”;//valuessql+=”select ?”;for(int i=2;i<=count;i++){sql+=”,?”;}sql+=” where not exists (select 1 from “+tableName+” where “+pk+” = ? )”;return sql;}

这样的话,整个程序就变得很简洁。其实第四点是根据第二点的结构生成的。

本文出自 “每天进步一点点” 博客,请务必保留此出处

要知道,当你一直在担心错过了什么的时候,

用程序实现SQL的表导出

相关文章:

你感兴趣的文章:

标签云: