我这只是测试,把一个中英放入MYSQL数据库,,但在里面是乱码,于是我采用了最常用的byte来转一转,,但都还是乱码??应该好何做好呢??急啊...
<%
 Connection conn=null;
 Statement sql=null;
 ResultSet rs=null;
String abc=request.getParameter("textfield");
byte[] b=abc.getBytes("ISO-8859-1");
abc=new String(b);
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch (ClassNotFoundException e){}
try
{
String url="jdbc:mysql://localhost:3306/english";
conn=DriverManager.getConnection(url,"root","123456");

   
sql=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
out.print(abc);
rs=sql.executeQuery("Select * from text");

sql.executeUpdate("insert into text values"+"("+"'"+abc+"')");
}
catch (Exception e) {}
%>
这是我用来测试的代码,,应该好何改??

解决方案 »

  1.   

    在String abc=request.getParameter("textfield");之前加一句request.setCharacterEncoding("gb2312");试看看
      

  2.   

    呵呵,,行了,,,
    很多问多一句,,为什么在数据库里现在不是乱码,,但读出来的是??
    如out.println(request.getParameter("textfield"));
    出现: ??
    为什么呢?在mysql中已不是乱码的了,,
    请大家再帮一帮,,不够分再开一个给,,谢谢了
      

  3.   

    我用了这种转换可以显示出来了,,
    String abc=request.getParameter("textfield");
    if(abc==null)
    abc="";
    abc=new String(abc.getBytes("ISO-8859-1"), "GB2312");
    out.println(abc);
    但是如果在两种编码都可以支持的,,那我就不知是什么了,,如繁体五笔与简体五笔,,还是iso-8859-1,好似不是哦