Struts问题,急急急!!!在线等!!!

superlanneret 2004-12-29 02:11:39
错误如下:
sql.executeQuery:General error, message from server: "Illegal mix of collations (gb2312_chinese_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE) for operation '='"

executeQuery函数如下:
public ResultSet executeQuery(String sql)throws Exception{
rs=null;
try{
sql=new String(sql.getBytes("GBK"),"ISO8859_1");
conn=DriverManager.getConnection(sConnStr);
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex){
System.out.println("sql.executeQuery:"+ex.getMessage());
}

return rs;
}
SQL语句如下:
db.executeQuery("select * from admin where UserName='"+username+"' and PassWord='"+password+"'");
...全文
598 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
chocolate863 2005-01-05
  • 打赏
  • 举报
回复
顶,顶
chocolate863 2005-01-05
  • 打赏
  • 举报
回复
public static String changeToChinese(String targetStr)
{
try
{
String returnStr = "";
if (targetStr==null)
{
return null;
}
else
{

byte[] b = targetStr.getBytes("gb2312");
returnStr = new String(b,"iso-8859-1");
return returnStr;
}
}
catch(Exception ex)
{
return null;
}
}
用这个转换一下应该就可以了,我缺分罗
superlanneret 2005-01-04
  • 打赏
  • 举报
回复
上名的错误已经解决了通过换了一个Mysql的驱动程序但是出现了下面的错误:
sql.executeQuery:Communication failure during handshake. Is there a server running on zmh:3306?
superlanneret 2004-12-30
  • 打赏
  • 举报
回复
自己顶一下,出人命了
superlanneret 2004-12-30
  • 打赏
  • 举报
回复
我在Mysql的my.ini文件中修改了字符集,但是还是不行?难道不是在my.ini文件中修改字符集吗?救命啊!!要死人了
itjourney 2004-12-30
  • 打赏
  • 举报
回复
数据库的字符集和SQL语句的字符集不一致,我以前在SQL Server上碰到过。
yanghan78 2004-12-30
  • 打赏
  • 举报
回复
在try{后面加一句:Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
试试看吧
sgdb 2004-12-30
  • 打赏
  • 举报
回复
设置mysql的字符集为gbk,然后sql不要转化,直接查询就可以了
superlanneret 2004-12-30
  • 打赏
  • 举报
回复
谢谢各位大虾,你们的方法我都试了,还是不行!!!!!依然是不行!!!!救命啊!
eyangm 2004-12-30
  • 打赏
  • 举报
回复
楼主先把你转了以后的sql 打印出来看看撒~~~~
把username,password,分别用new String(xxx.getBytes("GBK"),"ISO8859_1");
来转码看看`~~~~
lgstat888 2004-12-30
  • 打赏
  • 举报
回复
不用转换,试一试,应该可以.
superlanneret 2004-12-30
  • 打赏
  • 举报
回复

自己顶一下,出人命了

alpha15 2004-12-29
  • 打赏
  • 举报
回复
不使用这个转换可不可以?

或者
sql=new String(sql.getBytes("gb2312"))?
dongdongmaster 2004-12-29
  • 打赏
  • 举报
回复
1:去掉sql=new String(sql.getBytes("GBK"),"ISO8859_1");
2:SQL语句中:db.executeQuery("select * from admin where UserName='"+username+"' and PassWord='"+password+"'");,注意,and 和PassWord 之间要有一空格
试试看.
superlanneret 2004-12-29
  • 打赏
  • 举报
回复
试了,不行!!!还有别的解决办法吗?
programeyonger 2004-12-29
  • 打赏
  • 举报
回复
sql=new String(sql.getBytes("GBK"),"ISO8859_1");
gbk和iso的位置改换,试试?
或者干脆不用生成新的sql,直接传试试?
superlanneret 2004-12-29
  • 打赏
  • 举报
回复
自己在顶一下!!!要不就沉底了
superlanneret 2004-12-29
  • 打赏
  • 举报
回复
我曾试着把sql=new String(sql.getBytes("GBK"),"ISO8859_1");去掉过但是也不好使!!我试试把他俩调换一下
nwsl 2004-12-29
  • 打赏
  • 举报
回复
sql=new String(sql.getBytes("GBK"),"ISO8859_1");
gbk和iso的位置改换,试试?
或者干脆不用生成新的sql,直接传试试?
superlanneret 2004-12-29
  • 打赏
  • 举报
回复
没人回答!自己顶一下
加载更多回复(2)

67,513

社区成员

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

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