在向数据库查询时,传入的中文变成乱码,求解决方案

f741429220 2012-06-10 04:22:17
ps=conn.prepareStatement("select * from user where pwd=?,nickname=?");
ps.setString(1, pwd);
ps.setString(2, nickname);
pwd 是英文,nickname是中文,每次查找的时候都提示You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' nickname = '???????‘?'' at line 1
这个问题,向数据库插入的时候就没有问题,不是为什么查找就不行,知道的大神帮下忙啊!
...全文
186 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
f741429220 2012-06-13
  • 打赏
  • 举报
回复
问题已经解决了,谢谢大家了!
zyczy1314 2012-06-10
  • 打赏
  • 举报
回复
不能用逗号,用and
脉动 2012-06-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
晕,你的SQL语句写错了,应该是select * from user where pwd=? and nickname=?
[/Quote]

本以为是lz讲的那样,好奇之下验证之,结果证明:1楼讲的是对的...
  • 打赏
  • 举报
回复
Connection con=DriverManager.getConnection(conURL);
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select *from vip");
int i=0;
while(rs.next())
{

s1=rs.getString("nickname");
s2=rs.getString("pwd");
i++;

}
  • 打赏
  • 举报
回复
朋友,你试试下面的方法
Connection con=DriverManager.getConnection(conURL);
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select *from user");
i=0;
while(rs.next())
{

s1=rs.getString("pwd");
s2=rs.getString("nickname");
i++;

}
即可得到你需要的字符串
f741429220 2012-06-10
  • 打赏
  • 举报
回复
不是那个原因,逗号和and 都行
Sheng450422 2012-06-10
  • 打赏
  • 举报
回复
晕,你的SQL语句写错了,应该是select * from user where pwd=? and nickname=?

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧