Java学习之路-SQL-表的简单查询

把数据库中的某张表的记录全部显示出来。
SQL/Test1.java

package cn.antraces.SQL;

import java.sql.*;

public class Test1 {

    public static void main (String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://127.0.0.1:3306/student?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT", "root", "wodiu");
        //System.out.println(connection);
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("select * from course");
        while (resultSet.next()) {
            System.out.print(resultSet.getString("cno"));
            System.out.println("\t" + resultSet.getString("cname"));
        }
    }
}
点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注