java实现sql批量插入参数
发布时间:2020-12-14 06:22:49 所属栏目:Java 来源:网络整理
导读:背景: ? ? ?需要更新一些不规范的时间格式,如将某个时间格式化为yy-MM-dd,实际上为 yy-MM-dd hh:mm:ss,并且需要提供回滚脚本。 例如:规范化时间的脚本如下: test test_date (account_date, , ) test_date test_date 这个脚本是ok,但执行时受到影响的行
背景: ? ? ?需要更新一些不规范的时间格式,如将某个时间格式化为yy-MM-dd,实际上为 yy-MM-dd hh:mm:ss,并且需要提供回滚脚本。 例如:规范化时间的脚本如下: test test_date(account_date,,) test_date test_date
这个脚本是ok,但执行时受到影响的行数如果有几百条甚至上千条记录的话,回滚脚本怎么写呢? 模板如下: test test_date id;
1.首先,从test表中查出上述的参数: id,test_date test test_date>'2017-06-01 00:00:00' AND test_date<'2017-09-07 00:00:00'
将结果导入到文本中,名为为param.txt 2.然后运行以下java程序,打印出可执行的回滚脚本 insertData() = FileReader("D:documentloaddata1.txt"= ="update test set test_date= '' where id='';"= =0= String[2= "''"((line = br.readLine()) != =line.split("t"=updateSql.replaceFirst(regexp,"'"+param[1]+"'"=first.replaceFirst(regexp,"'"+param[0]+"'"++
3.如果行数较多,需要打印到文件中(Console打印的记录数受限的) insertData() = FileReader("D:documentloaddata1.txt"= =="update test set test_date= '' where id='';"= =0= String[2= "''"((line = br.readLine()) != =line.split("t"=updateSql.replaceFirst(regexp,"'"+param[0]+"'"
sbf.append(second).append("n"++"D:documentloadrollback.sql" </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> writeFile(String fileName,StringBuffer stf)
</span><span style="color: #0000ff;">throws</span><span style="color: #000000;"> IOException {
BufferedWriter writer </span>= <span style="color: #0000ff;">new</span> BufferedWriter(<span style="color: #0000ff;">new</span><span style="color: #000000;"> FileWriter(fileName));
writer.write(stf.toString());
writer.close();
}</span></pre>
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容