Notice
Recent Posts
Recent Comments
Link
«   2024/06   »
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
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter05 : select 본문

JAVA/chapter27_preparestatement

chapter05 : select

GAWON 2023. 5. 31. 09:39
package org.joonzis.ex;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.joonzis.db.DBConnection;

public class Ex04_select {
	public static void main(String[] args) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null; 

		try {
			conn = DBConnection.getConnection();
			ps = (PreparedStatement) conn.createStatement();

			String sql = "select * from person";
			
			rs = ps.executeQuery(sql);

		

			while (rs.next()) {
				System.out.print(rs.getString(1) + ",");
				System.out.print(rs.getInt(2) + ",");
				System.out.println(rs.getString(3));
			}

			
		} catch (Exception e) {
			e.printStackTrace();
			
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (conn != null) {
					conn.close();
				}
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}

	}
}

'JAVA > chapter27_preparestatement' 카테고리의 다른 글

chapter04 : delete  (0) 2023.05.31
chapter03 : update  (0) 2023.05.31
chapter02 : insert  (0) 2023.05.31
chapter01 : DBConnection  (0) 2023.05.31