1

I am doing an operation to first delete a record then insert in to the same table like this:

String delete = "DELETE FROM t WHERE t.id = id"
String insert = "INSERT INTO t VALUES (id, value1, value2)"

Statement s = conn.createStatement();
s.executeUpdate(delete);
s = conn.createStatement();
s.executeUpdate(insert);

then my application just blocked there after executing the insert statement. no response at all.

does any one know whats going on?

the db is oracle 11g.

1
  • 1
    "then my application just blocked there". Umm, care to point out at which line has the app blocked? May 18, 2011 at 20:35

6 Answers 6

2

The code below does not need the WHERE clause since you will delete all recorde from t where the id is equal to the id. Was that the intent or did you want to delete a specific id?

DELETE FROM t WHERE t.id = id
0
1

do s.close() after the deletion and insertion

1

you are misusing the sql statements

String delete = "DELETE FROM t WHERE t.id = ?"
String insert = "INSERT INTO t VALUES (?, ?, ?)"

PreparedStatement s = null;
try{
    s = conn.prepareStatement(delete);
    s.setNString(1,id);
    s.executeUpdate();
}finally{if(s!=null)s.close();s = null;}
try{
    s = conn.prepareStatement(insert );
    s.setNString(1,id);
    s.setNString(2,value1);
    s.setNString(2,value2);
    s.executeUpdate();
}finally{if(s!=null)s.close();s = null;}

in your code you didn't pass anything from your local vars and the sql server didn't know where to get the values of id, value1 and value2

1

s.executeUpdate(delete); are you sure that you didn't got some SQLException here, because this "DELETE FROM t WHERE t.id = id" seems as invalid statement

1

I found the reason. the AUTOCOMMIT flag is set to OFF.

1
  • How does that affect anything? Unless you are executing the two statements in separate sessions which would seem highly unlikely given the code sample you posted. May 18, 2011 at 23:00
0

If the database halts during heavy DML it may be due to the archive destination being full. Move archives to backup and the database will continue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.