JDBC中的批处理是什么-创新互联

这篇文章将为大家详细讲解有关JDBC中的批处理是什么,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

10年的钟楼网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整钟楼建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“钟楼网站设计”,“钟楼网站推广”以来,每个客户项目都认真落实执行。

直接上代码:

package
cn.zhou.epet.test;
import
java.sql.*;
public
class Addbatch {public
static void main(String[] args) {Connection connection =
null;PreparedStatement stmt =
null;try
{//
加载数据库相关驱动Class.forName("oracle.jdbc.driver.OracleDriver");//
连接到数据库connection =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:bdqn",
"epet", "admin");stmt =
connection.prepareStatement("insert
into master values(master_seq.nextval,?,?,?)");
connection.setAutoCommit(false);//
Transaction Begin,让程序不自动提交事务stmt.setString(1,
"QQ");stmt.setString(2,
"RR");stmt.setInt(3,
1);stmt.addBatch();//
添加批处理1
stmt.setString(1,
"WW");stmt.setString(2,
"EE");stmt.setInt(3,
1);stmt.addBatch();//
添加批处理2
stmt.setString(1,
"VV");stmt.setString(2,
"AA");stmt.setInt(3,
1);stmt.addBatch();//
添加批处理3stmt.executeBatch();//
执行批处理
connection.commit();//
提交事务
connection.setAutoCommit(true);//
Transaction End,让程序自动提交事务(默认)System.out.println("dd");} catch
(ClassNotFoundException e) {e.printStackTrace();System.out.println("未能成功加载驱动类!");} catch
(SQLException e) {e.printStackTrace();System.out.println("执行SQL语句是出现异常!");try
{if
(connection != null) {connection.rollback();//
事务回滚connection.setAutoCommit(true);//
让程序自动提交事务(默认)}} catch
(SQLException e1) {e1.printStackTrace();}} catch
(Exception e) {e.printStackTrace();System.out.println("其他异常!");}
finally {try
{if (stmt
!= null) {stmt.close();stmt =
null;}if
(connection != null) {connection.close();connection =
null;}} catch
(SQLException e2) {System.out.println("关闭数据库时出现异常!");}}}
}JDBC中的批处理是什么

关于“JDBC中的批处理是什么”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

分享题目:JDBC中的批处理是什么-创新互联
转载来源:https://www.cdcxhl.com/article6/dsjeog.html

成都网站建设公司_创新互联,为您提供企业建站标签优化做网站手机网站建设外贸建站外贸网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

手机网站建设