package CHAPTER15;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SelectQuery {
	private static final String URL = "jdbc:mysql://localhost:3306/course";
	private static final String USER = "root";
	private static final String PASSWORD = "123456789";

	// 모든 회원 정보 조회
	public static void getAllMembers(Connection connection) throws SQLException {
		String query = "SELECT * FROM members";

		Statement statement = connection.createStatement();
		ResultSet resultSet = statement.executeQuery(query);

		System.out.println("\nAll Members:");
		while (resultSet.next()) {
			System.out.println("ID: " 
					+ resultSet.getInt("member_id") + ", Username: " 
					+ resultSet.getString("username")
					+ ", Email: " + resultSet.getString("email") + ", Phone: " + resultSet.getString("phone")
					+ ", Birthdate: " + resultSet.getDate("birthdate"));
		}
	}

	public static void main(String[] args) throws SQLException {
		try {
			Connection connection = DriverManager.getConnection(URL, USER, PASSWORD);
			getAllMembers(connection);
	    } catch (SQLException e) {
	        System.err.println("Database connection failed: " + e.getMessage());
	        e.printStackTrace();
	    }
	}
}
