原代码
import java.sql.*;
public class ex {
public static void main(String[] argv){
Connection con;
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception e){}
String uri = "jdbc:mysql://192.168.100.1:3306/example?useSSL=true";
String user = "host";
String password = "******";
try{
con = DriverManager.getConnection(uri,user,password);
Statement sql = con.createStatement();
ResultSet rs = sql.executeQuery("select * from student");
while(rs.next()){
String name = rs.getString(1);
String sex = rs.getString(2);
int id = rs.getInt(3);
System.out.println(name+" "+sex+" "+id);
}
con.close();
}catch(SQLException e){
System.out.println(e);
}
}
}
然后出现了如下问题
纠结了一会 重启mysql 没有解决
然后修改为之前用的代码
import java.sql.*;
public class ex {
public static void main(String[] argv){
Connection con;
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception e){}
/********/
String uri = "jdbc:mysql://localhost:3306/example?useSSL=true";
/********/
String user = "host";
String password = "******";
try{
con = DriverManager.getConnection(uri,user,password);
Statement sql = con.createStatement();
ResultSet rs = sql.executeQuery("select * from student");
while(rs.next()){
String name = rs.getString(1);
String sex = rs.getString(2);
int id = rs.getInt(3);
System.out.println(name+" "+sex+" "+id);
}
con.close();
}catch(SQLException e){
System.out.println(e);
}
}
}
就成功了