Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java program hangs on executeUpdate without exception

I have a simple program that does database update using Oracle Driver. It is a long running sql that works in SQLDeveloper mode but hang on executing in Java program:

String sql = "UPDATE ...";
PreparedStatement ps = conn.prepareStatement(sql);
log.info(sql);

int affectedRows = ps.executeUpdate();
log.info("affected rows = " + affectedRows);

It logs the sql line, but never prints the affected rows line.

In the database it shows the execution (V$SESSION_LONGOPS) is completed with 0 remaining time:

enter image description here

However weird thing is this session only exists in V$SESSION_LONGOPS but not V$SESSION. And apparently this never gets back to the Java program. In the running system of the program, ps -ef gives this info:

user 5889  5885  0 00:00 ?        00:00:11 /java/jdk1.6.0_25/bin/java -cp ...

It shows it started running at 00.00 (scheduled by Cron) and only executed for 11 seconds (and now it is 10am which 10h has passed). It seems like the program just hangs/dies, and no exception is given in the log (a big try catch is surrounded with log exception).

It never reaches to the end of program because ps still prints this and there is no logs of the coming line.

Would appreciate any help that points to the direction.

like image 796
SwiftMango Avatar asked Feb 20 '15 15:02

SwiftMango


3 Answers

You can check below tables whether your session is in waiting mode or not.

select * from dba_blockers; select * from dba_waiters;

Make sure your session is not in above query.

and also check whether your objects is not locked with below query

select * from v$locked_object in this view you can get locked object id and from dba_objects you are able to get object name.

if you found any session in this then please kill or finish that session first.

like image 171
Jaimin Soni Avatar answered Oct 13 '22 01:10

Jaimin Soni


I had the same problem you had, I don't know about others but I solved it by simply closing SQLplus! I didn't think that could solve it since some queries worked while sqlplus was running on the console, but I closed it and now every queries work and nothing hangs!

You may want to try this if you have our problem!

like image 31
Phil Avatar answered Oct 12 '22 23:10

Phil


I had the same problem. executeUpdate was just hanging and there was no error.

The problem: I was at the same time connected with sqlDeveloper to the same db and had the same table open. As soon as I disconnected sqlDeveloper from the DB, the statements could be inserted and the java application went on working fine.

like image 2
Gero Avatar answered Oct 13 '22 01:10

Gero