package com.sf;

import com.sf.config.SpringConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author WanJl
 * @version 1.0
 * @title Main
 * @description
 * @create 2025/11/30
 */
public class Main {
    public static void main(String[] args) throws SQLException {
        ApplicationContext context=
                new AnnotationConfigApplicationContext(SpringConfig.class);
        //通过bean的所属类型获取bean对象
        DataSource ds = context.getBean(DataSource.class);
        //通过数据源获取到连接
        Connection connection = ds.getConnection();
        //通过连接创建Statement
        Statement statement = connection.createStatement();
        //执行sql语句
        ResultSet resultSet = statement.executeQuery("select * from tea");
        //遍历查询结果
        while (resultSet.next()) {
            System.out.println(resultSet.getString(2));
        }
        connection.close();
    }
}
