ResultSet rs = stmt.executeQuery("select username '用户名',password '密码',usertype '用户类别' from t_user order by id desc"); ======>>>>>>>>>>>ResultSet rs = stmt.executeQuery("select username as '用户名',password as '密码',usertype as '用户类别' from t_user order by id desc");
这个不行,试过了,jdbc指定为GBK是什么意思?
就好了,谢谢各位!
import com.redv.sql.encoding.*;Class.forName("org.gjt.mm.mysql.Driver");
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
//接管数据库连接实例
boolean coding = true;
EncodingConnection codingConnection = new EncodingConnection(con, coding, "ISO-8859-1", "GBK");
//获得接管后的数据库连接实例,以后直接使用con已经是经过EncodingConnection重新包装过的实例
con = codingConnection.getConnection();
pstmt = con.prepareStatement("SELECT f3, f4 FROM tbl1 WHERE f1 = ? AND f2 = ?");
pstmt.setString(1, f1);
pstmt.setString(2, f2);
rs = pstmt.executeQuery();
String f3, f4;
while(rs.next()) {
f3 = rs.getString(1);
f4 = rs.getString(2);
}
}
finally {
//close resouces
...
}