728x90
반응형
[회원정보테이블]
--회원정보테이블 CREATE TABLE TB_MEMBER ( m_seq NUMBER CONSTRAINT pk_member_seq PRIMARY KEY, --한 테이블당 한 개만 사용 가능 m_userid VARCHAR2(20) NOT NULL, m_pwd VARCHAR2(20) NOT NULL, m_email VARCHAR2(50), m_hp VARCHAR2(20), m_registdate DATE DEFAULT sysdate, m_point NUMBER DEFAULT 0 );
CREATE SEQUENCE seq_tb_member nocache;
INSERT INTO TB_MEMBER (m_seq, m_userid, m_pwd, m_email, m_hp) VALUES (seq_tb_member.NEXTVAL, 'apple', '1111', 'apple@apple.com', '010-8888-9999'); --NEXTVAL 번호 순차입력, PRIMARY KEY -중복값 X
package dbc4; import java.sql.*; public class MemberInsertPstmt4 { public static void main(String[] args) { try { Connection conn = DBConnec1.getConnection(); String userid = "orange"; String pwd = "3333"; String email = "orange@sun.com"; String hp = "010-3333-4444"; // String클래스의 format메서드를 사용하여 보기좋게 작성. String sql = String.format("INSERT INTO TB_MEMBER (m_seq, m_userid, m_pwd , m_email, m_hp, m_registdate, RDATE) " + "values (SEQ_TB_MEMBER.nextval, :userid, :pwd, :email, :hp, " + "to_date(:rdate,'YYYY-MM-DD HH24:MI:SS'), " + "TO_TIMESTAMP(:rdate,'YYYY-MM-DD HH24:MI:SS.FF9'))"); PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, userid); pstmt.setString(2, pwd); pstmt.setString(3, email); pstmt.setString(4, hp); pstmt.setString(5, "2000-05-01"); pstmt.setString(6, "2023-08-15 18:20:23.123456789 "); int count = pstmt.executeUpdate(); System.out.println(count + "개 행 입력"); pstmt.close(); } catch (Exception e) { System.out.println(e.toString()); } finally { try { DBConnec1.close(); } catch (Exception e) { } } } }
728x90
반응형
'[JDBC]' 카테고리의 다른 글
[JDBC] FUNCTION (0) | 2024.02.02 |
---|---|
[JDBC] TRANJACTION - COMMIT, ROLLBACK, 원자성 (0) | 2024.02.01 |
[JDBC] DAO, DTO (0) | 2024.01.31 |
[JDBC] Ex (0) | 2024.01.31 |
[JDBC] Statement, PreparedStatement (0) | 2024.01.30 |