package com.sf.jdbc.j20250906;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;

/**
 * @author WanJl
 * @version 1.0
 * @title Demo02_select
 * @description
 * @create 2025/9/6
 */
public class Demo02_select {
    private static String url="jdbc:mysql://127.0.0.1:3306/db03";   //服务器的统一资源定位符，帮我们找到服务器的内容
    private static String username="root";
    private static String password="123456";
    public static void main(String[] args) throws Exception{
        //1、注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2、获取连接
        Connection connection = DriverManager.getConnection(url, username, password);
        //3、创建执行
        Statement statement = connection.createStatement();
        //4、准备语句
        String sql="SELECT * FROM emp";
        //5、执行SQL，获取结果集
        ResultSet resultSet = statement.executeQuery(sql);
        //6、处理结果集
        while (resultSet.next()){
            //获取员工id
            int id = resultSet.getInt(1);
            String ename = resultSet.getString(2);
            int jobId = resultSet.getInt(3);
            int mgr = resultSet.getInt(4);
            Date joinDate=resultSet.getDate(5);
            double salary=resultSet.getDouble(6);
            double bonus=resultSet.getDouble(7);
            int deptId = resultSet.getInt(8);



            System.out.printf("员工id：%d，员工姓名：%s，职务id：%d，上级领导id：%d，入职时间：%s，工资：%f，奖金：%f，部门id：%d \n",
                    id,ename,jobId,mgr,joinDate,salary,bonus,deptId);
        }


        //7、释放资源
        resultSet.close();
        statement.close();
        connection.close();
    }
}
