select a.user_id,a.user_name,a.user_no,a.user_pswd,a.exp_time,a.user_sex,a.char_id,a.user_status,a.user_tel,a.user_email,a.user_type,b.char_name from user_info a,char_info b where a.char_id=b.char_id and a.user_no like '%%' and a.user_name like '%李%' and a.user_status=1 group by a.user_id; 英文的和数字的都可以啊, 我数据库和工具的编码是GBK
还有, 你提的问题很烂, 很烂
导致查不出结果有N种可能, 你要别人一个一个跟你说吗??
所以..
代码..
代码..
代码..
String user_name = request.getParameter("user_name");
String user_status = request.getParameter("user_status");
if (user_no == null)
user_no = "";
if (user_name == null)
user_name = "";
if (user_status == null)
user_status = "1";
Connection conn = null;
Statement stmt = null;
try {
conn = DBPool.getPool().getConnection();
stmt = conn.createStatement();
String strSqlUserChar = "select a.user_id,a.user_name,a.user_no,a.user_pswd,a.exp_time,a.user_sex,a.char_id,a.user_status,a.user_tel,a.user_email,a.user_type,b.char_name from user_info a,char_info b where a.char_id=b.char_id and "
+ "a.user_no like '%"
+ user_no
+ "%' and a.user_name like '%"
+ StringUtil.UniToGb(user_name)
+ "%' and a.user_status="
+ user_status
+ " group by a.user_id;";
StringUtil.UniToGb(strSqlUserChar);
System.out.print(strSqlUserChar);
ResultSet userResultSet = stmt.executeQuery(strSqlUserChar);
ArrayList userInfos = new ArrayList();
while (userResultSet.next()) {
你看代码哪里有错误, 以前一直是那样子的啊!
后面的几个参数
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/hystation?useUnicode=true"
username="root" password="admin" maxActive="20" maxIdle="10"
maxWait="-1"/> 我的是这样子的!
个加上试试。这两个参数应该一起用。
还有,StringUtil.UniToGb(strSqlUserChar);这个方法不知道是什么,在这个方法前后把SQL打印出来看看。
却
StringUtil.UniToGb(user_name)
编码不一致吧?
英文的和数字的都可以啊, 我数据库和工具的编码是GBK
正确答案是:
url="jdbc:mysql://127.0.0.1:3306/hystation?autoReconnect=true&useUnicode=true&characterEncoding=utf8"