zoukankan      html  css  js  c++  java
  • 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、运行结果

  • 相关阅读:
    JDK6和JDK7中的substring()方法
    考试结束
    今天之总结
    暂别
    珍惜
    放弃
    我男神
    心态
    稳住,我或许能赢
    还是做好自己吧
  • 原文地址:https://www.cnblogs.com/yanguobin/p/12005685.html
Copyright © 2011-2022 走看看