jdbc简单使用
Posted 请叫我小老弟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jdbc简单使用相关的知识,希望对你有一定的参考价值。
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、运行结果
以上是关于jdbc简单使用的主要内容,如果未能解决你的问题,请参考以下文章