jdbc简单使用
时间:2021-07-01 10:21:17
帮助过:17人阅读
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简单使用
标签:mamicode root void ext imp statement src otf driver