JDBC(Oracle 数据库)中的批处理…
来源:互联网 发布:广告牌生成器软件 编辑:程序博客网 时间:2024/05/18 18:44
直接上代码:
packagecn.zhou.epet.test;
importjava.sql.*;
publicclass Addbatch {
publicstatic 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("insertinto 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();//添加批处理3
stmt.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("关闭数据库时出现异常!");
}
}
}
}
0 0
- JDBC(Oracle 数据库)中的批处理…
- JDBC 数据库批处理操作
- jdbc(Oracle数据库)
- oracle jdbc connection
- JDBC 连接SQLServer数据库(F…
- oracle 数据库 访问不到…
- JDBC操作数据库的批处理
- jdbc 连接 oracle rac
- Jdbc操作数据库 增
- oracle 中的INTERVAL 函…
- 批处理操作Oracle数据库
- oracle数据库备份批处理
- JDBC批处理---(java 对数据库的回滚)
- JDBC批处理---(java 对数据库的回滚)
- JDBC 之插入Blob(图片)& 批处理 & 数据库事务
- Oracle中的批处理 ,using
- Oracle中的批处理,using
- 连接oracle数据库出现oracle …
- usaco-1.3.2-Barn Repair(贪心算法)
- Java中的代理
- 类的内省及反射
- 阿里巴巴2014年3月29日笔试题
- 黑马程序员之Java--交通灯管理系统需求分析及总结
- JDBC(Oracle 数据库)中的批处理…
- 在Java JDBC 中使用slf4…
- Tomcat集群配置
- Java Web 中的监听(Listener)
- 奥斯科技-防盗链开发(使用)
- Java内省机制
- 笔试题之 ip 快速查找
- 奥斯科技-开发类似于struts1.2的简…
- uva 11261 Bishops