static int TRANSACTION_NONE
A constant indicating that transactions are not supported.
static int TRANSACTION_READ_COMMITTED
A constant indicating that dirty reads are prevented; non-repeatable reads and phantom reads can occur.
static int TRANSACTION_READ_UNCOMMITTED
A constant indicating that dirty reads, non-repeatable reads and phantom reads can occur.
static int TRANSACTION_REPEATABLE_READ
A constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur.
static int TRANSACTION_SERIALIZABLE
A constant indicating that dirty reads, non-repeatable reads and phantom reads are prevented.
A constant indicating that transactions are not supported.
static int TRANSACTION_READ_COMMITTED
A constant indicating that dirty reads are prevented; non-repeatable reads and phantom reads can occur.
static int TRANSACTION_READ_UNCOMMITTED
A constant indicating that dirty reads, non-repeatable reads and phantom reads can occur.
static int TRANSACTION_REPEATABLE_READ
A constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur.
static int TRANSACTION_SERIALIZABLE
A constant indicating that dirty reads, non-repeatable reads and phantom reads are prevented.
try
{
conn.setAutoCommit(false);
Statement stat = conn.createStatement();
stat.executeUpdate(command1);
stat.executeUpdate(command2);
stat.executeUpdate(command3);
. . .:
stat.addBatch(command);
上面的还可以换成是下面这样。
/*
while (. . .)
{
command = "INSERT INTO . . . VALUES (" + . . . + ")";
stat.addBatch(command);
}
int[] counts = stat.executeBatch();
*/
conn.commit();
}catch(SQLException exp)
{
conn.rollback();
}
finnally
{
conn.close();
}
try
{
...
}
catch(SQLException exp)
{
conn.rollback();//出错行
}
finnally
{
conn.close();//出错行。
}
编译时出现错误:unreported exception java.sql.SQLException;must be caught or declared to be thrown。
是不是要在conn.rollback()外面再写一次try catch 语句?这也太繁琐了吧?还是你给我得不对?