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"));
        }
    }
}
按讚

發佈留言

電子郵件地址不會被公開。必填項已用 * 標註