在一个servlet中,如何只向数据库提交一次,就同时执行多个SQL语句 使用INSERT INTO table(fieldname,fieldname2,...) select fieldname,fieldname2,... from table 2 where ...可以将100条记录一次插入表中 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不行啊,我的table 2在另一个主机的另一个数据库中 JDBC 2.0不是支持成批更新吗?conn.setAutoCommit(false);stmt = conn.createStatement();stmt.addBatch("insert into ...");stmt.addBatch("insert into ...");...stmt.executeBatch();conn.commit();conn.setAutoCommit(true); 可以:public ResultSet executeQuery(String sql) {rs = null; try { rs.begin();//事务处理 while(..) rs = stmt.executeQuery(sql); rs.commit(); } catch(SQLException ex) { rs.rollback(); System.err.println("aq.executeQuery:"+ex.getMessage()); } return rs; }注意:1。update data时要加事务处理 2。象楼上说的,优化SQL 不行啊,我的table 2是在另一台主机的另一个数据库中 哈哈------有意思。1,你自己做一个连接池2,like this :rs = stmt.executeQuery(sql,“host ip”,"database name");3,注意,如果网断了,你的连接池如何处理 当时俺被逼的没有办法了,只好用SQL中的union来把一片查询语句连起来,批处理不能用于查询,事务好像也是一条一条的提交,结果还不是在一个ResultSet中,我记得那个玩意好像有个getMoreResultSet方法,但还是不在一个ResultSet中,至于插入删除修改可以用批处理。 qiyao(享受每一天),rs.begin(),stmt.executeQuery(sql,“host ip”,"database name")所用的这两个方法我怎么没有在doc里见的过,请指教以下。 模块化编程, 我要实现如下的功能该怎么做? 我租了一个服务器 域名 怎么把写好的jsp网站部署到服务器上 请教:如何实现将一个jsp或htm页文本框的值传递到一个java文件中? mysql中碰到的怪问题 java.sql.date 添加 数据库 datetime 如何在TEXTAREA中显示一个表格,用来显示数据? 有关在浏览器中打开word的问题? 执行ftp传文件问题,请教. 给点思路,不吝给分! .html文件如何调用servlet? 谁有数据库连接通用Bean 急!
conn.setAutoCommit(false);
stmt = conn.createStatement();
stmt.addBatch("insert into ...");
stmt.addBatch("insert into ...");
...
stmt.executeBatch();
conn.commit();
conn.setAutoCommit(true);
public ResultSet executeQuery(String sql)
{rs = null;
try
{ rs.begin();//事务处理
while(..)
rs = stmt.executeQuery(sql);
rs.commit();
}
catch(SQLException ex)
{
rs.rollback();
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
注意:1。update data时要加事务处理
2。象楼上说的,优化SQL
有意思。
1,你自己做一个连接池
2,like this :rs = stmt.executeQuery(sql,“host ip”,"database name");
3,注意,如果网断了,你的连接池如何处理