Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.PreparedStatement;
  5.  
  6. public class Insert_Te {
  7.  
  8. public Insert_Te() {
  9. try{
  10. //1. JDBC 드라이브 로딩
  11. Class.forName("oracle.jdbc.driver.OracleDriver");
  12. //2. DB 연결
  13. String url = "jdbc:oracle:thin:@localhost:1521:orcl";
  14. String userName = "scott";
  15. String userPwd = "tiger";
  16. Connection conn = DriverManager.getConnection(url,userName,userPwd);
  17.  
  18. //3. 쿼리문
  19. int num1 = 7665;
  20. String name1 = "김정일";
  21. int mgr = 7698;
  22. String job = "garbage";
  23. int sal = 56605;
  24. int comm = 13;
  25. int depno = 30;
  26. String emailk = "adf@naver.com";
  27.  
  28. String sql = "insert into emp_test1 (empno, ename, job, mgr, hiredate, sal, comm, deptno, email)";
  29. sql += "values(?, ?, ?, ?, sysdate, ?, ?, ?, ?)";
  30.  
  31. PreparedStatement pstmt = conn.prepareStatement(sql);
  32. ///////sql 값세팅
  33. pstmt.setInt(1, num1);
  34. pstmt.setString(2, name1);
  35. pstmt.setString(3, job);
  36. pstmt.setInt(4, mgr);
  37. pstmt.setInt(5, sal);
  38. pstmt.setInt(6, comm);
  39. pstmt.setInt(7, depno);
  40. pstmt.setString(8, emailk);
  41.  
  42. //4. 실행
  43. int cnt = pstmt.executeUpdate();
  44. if(cnt > 0){
  45. System.out.println("레코드가 업데이트 되었습니다...");
  46. }else{
  47. System.out.println("레코드 업데이트의 실패");
  48. }
  49. //5. 종료(Close())
  50. pstmt.close();
  51. conn.close();
  52. }catch(Exception e){System.out.println(e.getMessage());}
  53. }
  54.  
  55. public static void main(String[] args) {
  56. new Insert_Te();
  57.  
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement