Statement.setQueryTimeout(seconds)在家中环境的再次试验 证明此语句还是有效的
对比实验:https://www.cnblogs.com/xiandedanteng/p/11955887.html
这次实验的环境是T440p上安装的Windows版Oracle11g,版本为:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
用于实验造成行锁的程序:
package com.hy.multidelete; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import org.apache.log4j.Logger; public class Deleter { private static Logger log = Logger.getLogger(Deleter.class); public void doDelete() { Connection conn = null; Statement stmt = null; try{ Class.forName(DBParam.Driver).newInstance(); conn = DriverManager.getConnection(DBParam.DbUrl, DBParam.User, DBParam.Pswd); conn.setAutoCommit(false); stmt = conn.createStatement(); String sql="delete from TestTB17 where id=1"; int deleted=stmt.executeUpdate(sql); // 在此处停住断点,另一个删除程序CleanExpiredMocker会执行不下去 log.info("Deleter deleted "+deleted+" records."); // 直到接下来回滚或提交CleanExpiredMocker才可以执行 conn.rollback(); log.info("Rollbacked."); } catch (Exception e) { System.out.print(e.getMessage()); } finally { try { stmt.close(); conn.close(); } catch (SQLException e) { System.out.print("Can't close stmt/conn because of " + e.getMessage()); } } } public static void main(String[] args) { Deleter d=new Deleter(); d.doDelete(); } }
设置了执行sql超时的程序:
package com.hy.multidelete; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import org.apache.log4j.Logger; public class CleanExpiredMocker { private static Logger log = Logger.getLogger(CleanExpiredMocker.class); public void doClean() { Connection conn = null; Statement stmt = null; try{ Class.forName(DBParam.Driver).newInstance(); conn = DriverManager.getConnection(DBParam.DbUrl, DBParam.User, DBParam.Pswd); stmt = conn.createStatement(); stmt.setQueryTimeout(2); String sql="delete from TestTB17 where id<250"; int deleted=stmt.executeUpdate(sql); log.info("CleanExpiredMocker deleted "+deleted+" records.");; } catch (Exception e) { System.out.print(e.getMessage()); e.printStackTrace(); } finally { try { stmt.close(); conn.close(); } catch (SQLException e) { System.out.print("Can't close stmt/conn because of " + e.getMessage()); } } } public static void main(String[] args) { CleanExpiredMocker c=new CleanExpiredMocker(); c.doClean(); } }
执行后,很快就终止了执行,输出如下:
ORA-01013: 用户请求取消当前的操作 java.sql.SQLException: ORA-01013: 用户请求取消当前的操作 at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521) at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:194) at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:1000) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307) at oracle.jdbc.driver.OracleStatement.executeUpdateInternal(OracleStatement.java:1814) at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:1779) at oracle.jdbc.driver.OracleStatementWrapper.executeUpdate(OracleStatementWrapper.java:277) at com.hy.multidelete.CleanExpiredMocker.doClean(CleanExpiredMocker.java:24) at com.hy.multidelete.CleanExpiredMocker.main(CleanExpiredMocker.java:41)
程序,有时候真是跑起来才知道结果。
--END-- 2019年11月29日21:11:10
Statement.setQueryTimeout(seconds)在家中环境的再次试验 证明此语句还是有效的的更多相关文章
- [JDBC/Oracle]设置Statement.setQueryTimeout(seconds)并不好用 原因:环境问题
对比实验:https://www.cnblogs.com/xiandedanteng/p/11960320.html 注:setQueryTimeout语句还是好用的,但有些环境不支持,下文是在单位虚 ...
- Linux中环境变量文件及配置
Linux中环境变量文件及配置 一.环境变量文件介绍 转自:http://blog.csdn.net/cscmaker/article/details/7261921 Linux中环境变量包括系统 ...
- Linux中环境变量文件及配置(转载)
一.环境变量文件介绍 转自:http://blog.csdn.net/cscmaker/article/details/7261921 Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登 ...
- Linux中环境变量中文件执行顺序
Linux 的变量可分为两类:环境变量和本地变量 环境变量:或者称为全局变量,存在于所有的shell 中,在你登陆系统的时候就已经有了相应的系统定义的环境变量了.Linux 的环境变量具有 ...
- 【学习总结】GirlsInAI ML-diary day-2-Python版本选取与Anaconda中环境配置与下载
[学习总结]GirlsInAI ML-diary 总 原博github链接-day2 Python版本选取与Anaconda中环境配置与下载 1-查看当前Jupyter的Python版本 开始菜单选J ...
- Node.js中环境变量process.env详解
Node.js中环境变量process.env详解process | Node.js API 文档http://nodejs.cn/api/process.html官方解释:process 对象是一个 ...
- Linux中环境变量文件
一.环境变量文件介绍 转自:http://blog.csdn.net/cscmaker/article/details/7261921 Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登 ...
- shell中环境变量
Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登录到系统的用户都要读取的系统变量,而用户级的环境变量则是该用户使用系统时加载的环境变量. 所以管理环境变量的文件也分为系统级和用户级的, ...
- u-boot中环境变量的实现
转载:http://blog.chinaunix.net/uid-28236237-id-3867041.html U-boot中通过环境参数保存一些配置,这些配置可以通过修改环境参数.保存环境参数. ...
随机推荐
- layui 多个文件上传控件 整合缩减代码
// 图片上传 upload.render({ elem: '.upload-img' // 点击上传的按钮统一使用该类 ,url: "{:url('image/upload')}" ...
- Mybatis,返回Map的时候,将Map内的Key转换为驼峰的命名
每次使用mybatis的时候,简单的连表查询,用Map接收的时候,都是像DB定义的字段一样,类似以下 student_name,student_id,没有转换为驼峰,但是又不能因为这一个定义一个jav ...
- zabbix-proxy及ELK
1.添加tomcat监控模版 yum install java-1.8.0-openjdk tomcat-webapps tomcat-admin-webapps tomcat-docs-webapp ...
- http通信示例Httpclient和HttpServer
本示例源于为朋友解决一个小问题,数据库到服务器的数据传输,由于本人能力有限,暂时将它理解为从数据库中获取数取表数据,实际上有可能是文件或者其他形式的数据,不过原理都得用流传输, 首先httpclien ...
- Linux命令——dmesg
参考:Linux kernel buffer ring Linux dmesg Command Tutorial for Beginners (5 Examples) 7 ‘dmesg’ Comman ...
- STL详细介绍(更新中~~~)
目录 string string的常见构造函数 string与char *(或const char*)之间的转换 string 转化为const char* const char* 转化为string ...
- IDEA 相关设置汇总
1.自动提示.代码补全 有时候希望使用自动补全,因为不偷懒的程序员不是好程序员.但是Idea的默认快捷键是 Ctrl + 空格. 对于安装中文输入法的普通人来说那就是杯具了,你懂的. 修改方法如下: ...
- mysql跨表删除多条记录
Mysql可以在一个sql语句中同时删除多表记录,也可以根据多个表之间的关系来删除某一个表中的记录. 假定我们有两张表:Product表和ProductPrice表.前者存在Product的基本信息, ...
- NOI.ac 模拟赛20181103 排队 翘课 运气大战
题解 排队 20% 1≤n≤20,1≤x,hi≤201\le n\le 20, 1\le x,h_i\le 201≤n≤20,1≤x,hi≤20 随便暴力 50% 1≤n≤2000,1≤x,hi≤1 ...
- go mod
https://blog.csdn.net/zzhongcy/article/details/97243826 来自为知笔记(Wiz)