Oracle执行update时卡死问题的解决方法

问题:

在执行delete或for update语句时,PLSQL一直执行,不出结果。

原因:

执行update或者insert语句后需要commit,如果因网络或其他原因没有commit而强制关闭连接,Oracle就会将该条提交的记录锁住。

解决方法:

1、查询锁定记录

select object_name, machine, s.sid, s.serial#
  from v$locked_object l, dba_objects o, v$session s
 where l.object_id  =  o.object_id
   and l.session_id = s.sid;

在这里插入图片描述

2、删除该锁定记录

alter system kill session 'SID,serial#';

其中 SID填写上面查到的SID数值,serial#填写serial#列的数值,如下:

alter system kill session '81,38364';
发布了691 篇原创文章 · 获赞 2949 · 访问量 410万+
展开阅读全文

java中事务未提交,但是在update之后再select为什么会得到update之后的结果?

02-03

想知道为什么会这样? 代码如下: ``` public static void main(String[] args) { String dbName = "F:/firstdb"; String driver = "org.apache.derby.jdbc.EmbeddedDriver"; String protocol = "jdbc:derby:"; try{ Class.forName(driver).newInstance(); System.out.println("Loaded the appropriate driver"); Connection conn = DriverManager.getConnection(protocol + dbName + ";"); System.out.println("Connected to and created database " + dbName); conn.setAutoCommit(false); Statement stat = conn.createStatement(); String command = "update my_test set NAME='1234' where ID='03'"; stat.executeUpdate(command); //conn.rollback(); PreparedStatement state = conn.prepareStatement("select * from my_test", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = state.executeQuery(); int i = 1; while(rs.next()){ if(i < 4){ System.out.printf(rs.getString(1) + " "); System.out.printf(rs.getString(2) + " "); System.out.printf(rs.getString(3) + " "); System.out.printf(rs.getString(4) + "\n"); i++; }else{ rs.relative(-2); System.out.println("finally"); System.out.printf(rs.getString(1) + " "); System.out.printf(rs.getString(2) + " "); System.out.printf(rs.getString(3) + " "); System.out.printf(rs.getString(4) + "\n"); break; } } }catch(Exception e){ e.printStackTrace(); } } ``` 结果如下: ``` Loaded the appropriate driver Connected to and created database F:/firstdb 01 男 10 LiSi 02 女 20 ZhangSan 03 男 40 1234 finally 02 女 20 ZhangSan ``` 如果把update相关语句注释掉,那么结果如下: ``` Loaded the appropriate driver Connected to and created database F:/firstdb 01 男 10 LiSi 02 女 20 ZhangSan 03 男 40 123 finally 02 女 20 ZhangSan ``` 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览