|
import java.sql.*;
public class Update {
public static void main(String[] args) throws SQLException {
Connection con = null;
Statement stm = null;
try {
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
con = DriverManager.getConnection( "jdbc:oracle:thin:@127.0.0.1:1521:ORCL","test","test");
// 自動コミットを無効にする。
con.setAutoCommit(false);
stm = con.createStatement();
// SQLの実行
int cnt = stm.executeUpdate("update emp set name = 'なまえ3' where emp_id = 'E01'");
// 更新件数の表示
System.out.println(cnt);
// コミットする。
con.commit();
} catch (SQLException ex) {
// 例外発生時はロールバックする。 con.rollback();
} finally {
if ( stm != null ) {
// Statement クローズ
stm.close();
}
if ( con != null ) {
// コネクションクローズ
con.close();
}
}
}
} |