I feel that this code is relatively fixed, so I will write it here. If you forget it, I can check it ~~~
Connection conn = NULL;
Statement stmt = NULL;
Resultset rs = NULL;
String url = NULL;
String user = NULL;
String Password = NULL;
String SQL = NULL;
List list = new arraylist ();
Try {
Class. forname ("com. MySQL. JDBC. Driver ");
Url = "JDBC: mysql: // localhost/userdb? User = root & Password = root & useunicode = true & characterencoding = gb2312 & autoreconnect = true "; // URL =" JDBC: myqsl: // localhost/test (Database Name )? User = root (User) & Password = root (password )";
User = "root ";
Password = "root ";
Conn = drivermanager. getconnection (URL, user, password );
Stmt = conn. createstatement ();
SQL = "select * From Table1 ";
Rs = stmt.exe cutequery (SQL );
While (Rs. Next ()){
User user = new user ();
User. setname (Rs. getstring (1 ));
User. setgender (Rs. getint (2 ));
......
List. Add (User );
}
}
Catch (exception E)
{
E. printstacktrace ();
}
Return list;