当前位置:首页 > 数据库 > 正文

jdbc简单使用

2020-02-12 数据库

1、代码

import java.sql.*;

public class DBUtil {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/imooc", "root", "123");
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select user_name, age from imooc_gaddess");
        while (resultSet.next()){
            System.out.println(resultSet.getString("user_name")   "年龄:"   resultSet.getInt("age"));
        }
    }
}

2、依赖

3、数据库

4、运行结果

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/SQL/15265.html