How to use Transaction to make a series of operations on the database in Java

xiaoxiao2021-03-06  60

Transaction's role:

For example

General format.

Try

{

Conn.setautocommit (false);

Statement stat = conn.createstatement ();

Stat.executeUpdate (Command1);

Stat.executeUpdate (Command2);

Stat.executeUpdate (Command3);

.

Stat.Addbatch (Command);

It can be replaced in the above.

/ *

While (....)

{

Command = "INSERT INTO... VALUES (" ... ")"

Stat.Addbatch (Command);

}

int [] counts = stat.executebatch ();

* /

CONN.COMMIT ();

} catch (SQLEXCEPTION EXP)

{

CONN. ROLLBACK ();

}

FINNALLY

{

CONN.CLOSE ();

}

转载请注明原文地址:https://www.9cbs.com/read-106481.html

New Post(0)