mysql问题:Connection conn = null;
PreparedStatement pstmt = null;
Statement stmt = null;
ResultSet rs = null;
ResultSet rs1 = null; try {
conn = com.iad.sql.PoolableDataSourceFactory.getResourceDataSource().getConnection();
String query = "select * from dict where name = '名称'";
stmt = conn.createStatement(); 
rs1 = stmt.executeQuery(query); 
pstmt = conn.prepareStatement(query);
rs = pstmt.executeQuery(); while (rs.next()) {
out.print(rs.getInt(1) + "--OK<br />");
}

while (rs1.next()) {
out.print(rs1.getInt(1) + "--OK");
}
} catch (SQLException sqle) {
out.println("sqle=" + sqle);
} finally {
try {
if (conn != null) {
conn.close();
}
if (stmt != null) {
stmt.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException sqle) {
out.println("sqle=" + sqle);
}
}
查询时不中文输入的两种结果,英文都没有问题.
rs结果为0,rs1结果为1
曲别在于两种连接方式:直接提交(createStatement)和预处理(prepareStatement)附:编码全部采用UTF-8,添加、修改(中文)都正常。能找到的资料都试过。数据库为mysql,同样代码,在sql server上正常!
实再不知道什么问题了。

解决方案 »

  1.   

    返回为空的就是指的编码不一致。
    进入MYSQL看看 精华帖子中关于怎么整编码的再说。
      

  2.   

    找到两个关键点:
    createStatement和prepareStatement
    createStatement提交可以正常得到result,而相同的链接,相同的SQL,用prepareStatement就不可以。而且只是中文不可以。编码方式已经试过!
    数据库和JSP都是UTF-8,相同问题好像很多,但没有根本解决的或说明原因的。
      

  3.   

    mysql> show variables like '%character%';
    +--------------------------+-----------------------------+
    | Variable_name            | Value                       |
    +--------------------------+-----------------------------+
    | character_set_client     | utf8                        |
    | character_set_connection | utf8                        |
    | character_set_database   | utf8                        |
    | character_set_filesystem | binary                      |
    | character_set_results    | utf8                        |
    | character_set_server     | utf8                        |
    | character_set_system     | utf8                        |
    | character_sets_dir       | D:\mysql5.0\share\charsets\ |
    +--------------------------+-----------------------------+
    8 rows in set (0.00 sec)mysql> show variables like '%collation%';
    +----------------------+-----------------+
    | Variable_name        | Value           |
    +----------------------+-----------------+
    | collation_connection | utf8_general_ci |
    | collation_database   | utf8_general_ci |
    | collation_server     | utf8_general_ci |
    +----------------------+-----------------+
    3 rows in set (0.00 sec)mysql编码已经是UTF8