Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- public class Insert_Te {
- public Insert_Te() {
- try{
- //1. JDBC 드라이브 로딩
- Class.forName("oracle.jdbc.driver.OracleDriver");
- //2. DB 연결
- String url = "jdbc:oracle:thin:@localhost:1521:orcl";
- String userName = "scott";
- String userPwd = "tiger";
- Connection conn = DriverManager.getConnection(url,userName,userPwd);
- //3. 쿼리문
- int num1 = 7665;
- String name1 = "김정일";
- int mgr = 7698;
- String job = "garbage";
- int sal = 56605;
- int comm = 13;
- int depno = 30;
- String emailk = "adf@naver.com";
- String sql = "insert into emp_test1 (empno, ename, job, mgr, hiredate, sal, comm, deptno, email)";
- sql += "values(?, ?, ?, ?, sysdate, ?, ?, ?, ?)";
- PreparedStatement pstmt = conn.prepareStatement(sql);
- ///////sql 값세팅
- pstmt.setInt(1, num1);
- pstmt.setString(2, name1);
- pstmt.setString(3, job);
- pstmt.setInt(4, mgr);
- pstmt.setInt(5, sal);
- pstmt.setInt(6, comm);
- pstmt.setInt(7, depno);
- pstmt.setString(8, emailk);
- //4. 실행
- int cnt = pstmt.executeUpdate();
- if(cnt > 0){
- System.out.println("레코드가 업데이트 되었습니다...");
- }else{
- System.out.println("레코드 업데이트의 실패");
- }
- //5. 종료(Close())
- pstmt.close();
- conn.close();
- }catch(Exception e){System.out.println(e.getMessage());}
- }
- public static void main(String[] args) {
- new Insert_Te();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement