import java.sql.*; //1
String url = "jdbc:mysql://localhost:3306/数据库名`?useUnicode=true&characterEncoding=UTF-8;
String username = "root";
String password = "root";
8.0以上
String url="jdbc:mysql://localhost:3306/student?"+"useSSL=false&serverTimezone=UTC";
String user="root";
String password="root";
Class.forName("com.mysql.cj.jdbc.Driver");
public static void main(String[] args) throws SQLException {
Connection connection=null;
Statement statement;
ResultSet rs;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (Exception e) {
System.out.println(e);
}
String url="jdbc:mysql://localhost:3306/student?"+"useSSL=false&serverTimezone=UTC";
String user="root";
String password="root";
try {
connection=DriverManager.getConnection(url,user,password);
}catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
try {
statement=(Statement) connection.createStatement();
rs=((java.sql.Statement) statement).executeQuery("select * from test where c_grade>60&&java_grade>60");
while(rs.next()) {
String name=rs.getString(2);
double c_grade=rs.getDouble(3);
double java_grade=rs.getDouble(4);
String stu_id=rs.getString(5);
System.out.println("所有成绩大于60的 学生: "+ " 姓名" +name+c_grade+" "+java_grade+" id "+stu_id);
}
connection.close();