51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

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

}


赞(2)
未经允许不得转载:工具盒子 » Java学习之路-SQL-表的简单查询