我的MYSQL数据标见表时使用的是LATIN1,用JAVA取出数据后可以正常显示,但用LIKE语句检索中文时总是不能正常检索记录,显示的总是无关的记录,如果我不想改变MYSQL配置,因为数据库里已经有很多记录,怎么能够做到中文正常检索?
public mysqltools(String dbtable,int pagesizes,int bz,String where)
{
tablename=dbtable;
pagesize=pagesizes;
tpbz=bz;
try
{
String where1=new String(where.getBytes("ISO8859_1"),"latin1");
ctx=new InitialContext();
ds = (DataSource)ctx.lookup("java:comp/env/poolmysql");
conn = ds.getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
if(tpbz==1){
strSql="select count(*) as zs from "+tablename+" where tp<>'' and (bt like '%"+where1+"%' or nr like '%"+where1+"%')";
SearchWhere=" and (bt like '%"+where1+"%' or nr like '%"+where1+"%')"; }
else
if(tpbz==0){
strSql="select count(*) as zs from "+tablename+" where tp='' and (bt like '%"+where1+"%' or nr like '%"+where1+"%')";
SearchWhere=" and (bt like '%"+where1+"%' or nr like '%"+where1+"%')"; }
else{
strSql="select count(*) as zs from "+tablename+" where (bt like '%"+where1+"%' or nr like '%"+where1+"%')";
SearchWhere=" where bt like '%"+where1+"%' or nr like '%"+where1+"%'"; }
rs = stmt.executeQuery(strSql);
rs.last();
rows=rs.getInt("zs");
pages=(rows+pagesize-1)/pagesize;
}
catch (Exception e)
{
e.printStackTrace();
}
}
public mysqltools(String dbtable,int pagesizes,int bz,String where)
{
tablename=dbtable;
pagesize=pagesizes;
tpbz=bz;
try
{
String where1=new String(where.getBytes("ISO8859_1"),"latin1");
ctx=new InitialContext();
ds = (DataSource)ctx.lookup("java:comp/env/poolmysql");
conn = ds.getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
if(tpbz==1){
strSql="select count(*) as zs from "+tablename+" where tp<>'' and (bt like '%"+where1+"%' or nr like '%"+where1+"%')";
SearchWhere=" and (bt like '%"+where1+"%' or nr like '%"+where1+"%')"; }
else
if(tpbz==0){
strSql="select count(*) as zs from "+tablename+" where tp='' and (bt like '%"+where1+"%' or nr like '%"+where1+"%')";
SearchWhere=" and (bt like '%"+where1+"%' or nr like '%"+where1+"%')"; }
else{
strSql="select count(*) as zs from "+tablename+" where (bt like '%"+where1+"%' or nr like '%"+where1+"%')";
SearchWhere=" where bt like '%"+where1+"%' or nr like '%"+where1+"%'"; }
rs = stmt.executeQuery(strSql);
rs.last();
rows=rs.getInt("zs");
pages=(rows+pagesize-1)/pagesize;
}
catch (Exception e)
{
e.printStackTrace();
}
}
如 s=Sting(s.getBytes(‘utf-8’),"LATIN1");