public static Connection getConnection(){
String url="jdbc:mysql://localhost:3306/java9";
String username="root";
String pwd="123456";
Connection conn=null:
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection(url,username,pwd);
} catch(ClassNotFoundException | SQLException e){e.peintStackTrace();
}
return conn;
}
static void close(Statement statement,Connection c){
try {
statement.close();
c.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
声明并赋值,
public ArrayList<Student> getAll(){
Connection con=DBUtil.getConnection();
ArrayList<Student> rs=new ArrayList<Student>();
String sql="select * from student2";