public String outStr(String strValue)
{
try
{
String strBuffer=strValue;
byte[] byteBuffer=strBuffer.getBytes("ISO8859-1");
String strReturn=new String(byteBuffer,"gb2312");
return strReturn;
}
catch(Exception e)
{
return null;
}
}
{
try
{
String strBuffer=strValue;
byte[] byteBuffer=strBuffer.getBytes("ISO8859-1");
String strReturn=new String(byteBuffer,"gb2312");
return strReturn;
}
catch(Exception e)
{
return null;
}
}
wpTp = rs.getString("wptp");
if(wpTp!=null&&!wpTp.equals("")){
wpTp = new String(wpTp.getBytes("iso8859_1"),"GBK");
}
import java.io.*;
import java.net.*;
import java.sql.*;
public class jdbc
{
public static void main(String args[])
{
*String url="jdbc:mysql:// /tzw?useUnicode=true&characterEncoding=GB2312";
try
{
Class.forName(" ");
Connection conn=DriverManager.getConnection(url,"root","");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select id,name,address from apple");
while (rs.next())
{
System.out.println(" ID :"+rs.getInt("id")+" 名字 : "+rs.getString("name")+" 地址 : "+rs.getString("address"));}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
e.getMessage();
e.printStackTrace();
}}
}
一个是在连接时,连接字符串加入?useUnicode=true&characterEncoding=gb2312,如下:
jdbc:mysql://192.168.1.180/hasons1?useUnicode=true&characterEncoding=gb2312一种是显示时使用:
new String(wpTp.getBytes("iso8859_1"),"GB2312")来转换,显示就可以了。