提示: 大佬可以自动略过哦
/** * @create 2020-10-05 16:22 */ public class JDBCUseJdbcUtils { public static void main(String[] args) throws SQLException { test01(); } private static void test01() { Connection connection = null; Statement statement = null; ResultSet rs = null; try { //调用jdbcUtils中getConnection() connection = JDBCUtils.getConnection(); String sql = "select * from account"; //创建执行sql语句的对象 statement = connection.createStatement(); //执行sql语句 rs = statement.executeQuery(sql); while (rs.next()) { //获取table表中的字段 int id = rs.getInt(1); String name = rs.getString("name"); double balance = rs.getDouble(3); System.out.println("我是" + name + "我的工号id是 " + id + "我的工资是:" + balance + "元"); } } catch (SQLException e) { e.printStackTrace(); } finally { //释放资源 JDBCUtils.close(statement,connection,rs); } } }