Connection conn = null;
Statement stmt = null;
conn = DriverManager.getConnection("~")
stmt = conn.createStatement();
INSERT
String sql = "insert into dmlemp(empno, ename, deptno)";
sql+= "valuessql+= " values(" +empno+",'" + ename + "'," + deptno+ ")";
stmt.executeUpdate(sql);
UPDATE
String sql = "update dmlemp set sal=0 where deptno="+deptno;
stmt.executeUpdate(sql);
DELETE
String sql = "delete from dmlemp where deptno="+deptno;
stmt.executeUpdate(sql);
Connection conn = null;
Statement stmt = null;
//ResultSet (x) >> DML
try{
Class.forName("oracle.jdbc.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","사용자이름","암호");
System.out.println("연결 여부 : false :" + conn.isClosed());
stmt = conn.createStatement();
/*
//INSERT
int empno=0;
String ename="";
int deptno=0;
Scanner sc = new Scanner(System.in);
System.out.println("사번 입력");
empno = Integer.parseInt(sc.nextLine());
System.out.println("이름 입력");
ename = sc.nextLine();
System.out.println("부서번호 입력");
deptno = Integer.parseInt(sc.nextLine());
//insert into emp(empno,ename,deptno) values(2000,'홍길동',30)
//조선시대나 .... 현대 (parameter 설정 ...) >> values(?,?,?)
String sql="insert into dmlemp(empno,ename,deptno) ";
sql+= " values(" +empno+",'" + ename + "'," + deptno+ ")";
int resultrow = stmt.executeUpdate(sql);
*/
//UPDATE
/*
int deptno = 20;
String sql = "update dmlemp set sal=0 where deptno=" + deptno;
*/
//DELETE
int deptno = 20;
String sql = "delete from dmlemp where deptno=" + deptno;
int resultrow = stmt.executeUpdate(sql);
if(resultrow > 0){
System.out.println("반영된 행의 수 : " + resultrow);
}else{
//POINT
//문제가 생긴것이 아니고(예외가 발생된 것이 아니라)
//반영된 행이 없다
System.out.println("반영된 행이 없다 ...");
}
}catch(Exception e){
System.out.println(e.getMessage());
//여기서 코드 처리
}finally{
if(stmt != null)try {stmt.close();}catch (Exception e) {}
if(conn != null)try {conn.close();}catch (Exception e) {}
}