connection conn = null;
try {
string username = "root";
string password = "111@test";
string jdbcurl = "jdbc:mysql://localhost:3306/test?useunicode=true&usessl=false&autoreconnect=true&characterencoding=utf-8";
class.forname("com.mysql.jdbc.driver").newinstance();
conn = drivermanager.getconnection(jdbcurl, username, password);
string sql = "select * from tb_user";
preparedstatement pstmt = conn.preparestatement(sql);
resultset rs = pstmt.executequery();
string result = "";
while (rs.next()) {
int id = rs.getint("id");
string name = rs.getstring("username");
string status = rs.getstring("phone");
result += id + "\t" + name + "\t" + status + "\n";
}
system.out.println(result);
而逆向工程的却不行:
userexample example = new userexample();
userexample.criteria criteria = example.createcriteria();
criteria.andidequalto(userid);
list<user> list = usermapper.selectbyexample(example);//这一步进去后就出不来了。。。