把数据库中的某张表的记录全部显示出来。
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"));
}
}
}