想将sql语句拼接为insert...values(),(),(),()...(); 10
但是我写的代码是这样的insert...values(1);insert...values(1)(2);...重复插入之前的;代码如下try{intj=0,k=0;int...
但是我写的代码是这样的insert...values(1); insert...values(1)(2);...重复插入之前的;代码如下
try {
int j =0, k= 0;
int count=reader.getRecordCount();
j=count/1000;
str = new StringBuffer("INSERT INTO " + tableName1 + " VALUES(");
while ((rowValues = reader.nextRecord()) != null) {
for (int i = 0; i < rowValues.length; i++) {
if (i != 0)
str.append(",");
str.append("'").append(String.valueOf(rowValues[i]).trim())
.append("'");
str.append("");
}
str.append(",'" + dataS + "'),(");
System.out.println(str);
if (j>=1000) {
k++;
rsbool = stmt.executeUpdate(str.toString().substring(0,str.length() - 2));
str = new StringBuffer(k +":"+"INSERT INTO " + tableName1 + " VALUES(");
j++;
}
}
rsbool = stmt.executeUpdate(str.toString().substring(0,str.length() - 2));
} catch (Exception e) {
e.printStackTrace();
} finally {
newConn.commit();
newConn.close();
} 展开
try {
int j =0, k= 0;
int count=reader.getRecordCount();
j=count/1000;
str = new StringBuffer("INSERT INTO " + tableName1 + " VALUES(");
while ((rowValues = reader.nextRecord()) != null) {
for (int i = 0; i < rowValues.length; i++) {
if (i != 0)
str.append(",");
str.append("'").append(String.valueOf(rowValues[i]).trim())
.append("'");
str.append("");
}
str.append(",'" + dataS + "'),(");
System.out.println(str);
if (j>=1000) {
k++;
rsbool = stmt.executeUpdate(str.toString().substring(0,str.length() - 2));
str = new StringBuffer(k +":"+"INSERT INTO " + tableName1 + " VALUES(");
j++;
}
}
rsbool = stmt.executeUpdate(str.toString().substring(0,str.length() - 2));
} catch (Exception e) {
e.printStackTrace();
} finally {
newConn.commit();
newConn.close();
} 展开
1个回答
展开全部
这个就是把你拼写语句的改变一下就可以了吧
while里面insert into 处的拼接修改一下
str = new StringBuffer(k +":"+"INSERT INTO " + tableName1 + " VALUES(");
把这里修改一下吧。
“:” 拼接个冒号是做什么呢?还是打错了,应该是逗号?
while ((rowValues = reader.nextRecord()) != null) {
for (int i = 0; i < rowValues.length; i++) {
str.append("'").append(String.valueOf(rowValues[i]).trim())
.append("'");
if (i != rowValues.length-1){
str.append(",");
}
}
str.append("'" + dataS + "'),(");
}
System.out.println(str);
while修改的, if(j>1000)那段没明白楼主想干嘛
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询