import java.io.*;
import java.sql.*;
public class ExecuteIUD {
Connection conn;
public ExecuteIUD() {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");
}
catch (SQLException e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}
public static void main(String[] args)
throws Exception, IOException {
ExecuteIUD iud = new ExecuteIUD();
iud.executeIUD(
"insert into PERSON_IDENTIFIER_TYPE " +
"(code, description, inactive_date) " +
"values ('EID', 'Employee ID', NULL)");
iud.executeIUD(
"insert into PERSON_IDENTIFIER_TYPE " +
"(code, description, inactive_date) " +
"values ('PHONE', 'Phone Number', NULL)");
iud.executeIUD(
"insert into PERSON_IDENTIFIER_TYPE " +
"(code, description, inactive_date) " +
"values ('SSN', 'Social Socurity Number', NULL)");
iud.executeIUD(
"update PERSON_IDENTIFIER_TYPE " +
"set description = 'Social Security Number' " +
"where code = 'SSN'");
iud.executeIUD(
"delete PERSON_IDENTIFIER_TYPE " +
"where code = 'PHONE'");
}
public void executeIUD(String sql) throws IOException, SQLException {
int rslt = 0;
Statement stmt = null;
System.out.println(sql);
try {
stmt = conn.createStatement();
rslt = stmt.executeUpdate(sql);
System.out.println(Integer.toString(rslt) + " rows affected");
System.out.println(" ");
}
catch (SQLException e) {
System.err.println(e.getMessage());
}
finally {
if (stmt != null)
try { stmt.close(); } catch (SQLException ignore) { }
}
}
protected void finalize()
throws Throwable {
if (conn != null)
try { conn.close(); } catch (SQLException ignore) { }
super.finalize();
}
} |