Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter03 : insert 본문

JSP/DB (1)

chapter03 : insert

GAWON 2023. 5. 24. 18:49
package org.joonzis.ex;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.joonzis.db.DBConnect;

public class Ex03_insert {
	public static void main(String[] args) {
		

				Connection conn = null;
				PreparedStatement ps = null;

				try {
					conn = DBConnect.getConnection();
					String sql ="insert into sample(no,name,reg_date) " +
						" values(sample_seq.nextval, ?, sysdate)";							

					ps = conn.prepareStatement(sql);
					ps.setString(1,"김씨");
					int result = ps.executeUpdate();
					if(result > 0) {
						System.out.println("데이터 추가 완료!");
					}else {
						System.out.println("데이터 추가 실패");
					}
					
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					try {
						if (ps != null) {
							ps.close();
						}
						if (conn != null) {
							conn.close();
						}

					} catch (Exception e2) {
						e2.printStackTrace();
					}
				}
			}
		

	}

'JSP > DB (1)' 카테고리의 다른 글

chapter05 : delete  (0) 2023.05.24
chapter04 : update  (0) 2023.05.24
chapter02 : create  (0) 2023.05.24
chapter01 : create  (0) 2023.05.24
DBConnect  (0) 2023.05.24