请问一下大家,mysql数据库如何才能更好的解决乱码问题,我写了一个连mysql的测试类,在里面插入中文,在控制台显示是好的,没有乱码,可是在数据库里查询到的却是乱码,不知道如何解决,而且我在程序里面也已经指定了字符编码的,还是没有效果.测试类:package demo;import java.sql.*;
import demo.NoticeBean;public class JDBCTest
{
public static void main(String[] args)
{
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;try
{
String driverName = "org.gjt.mm.mysql.Driver";
Class.forName(driverName).newInstance();
String url = "jdbc:mysql://localhost:3306/JavaWeb?useUnicode=true&characterEncoding=gb2312";
connection = DriverManager.getConnection(url,"root","root");
System.out.println("连接数据库成功");//用到的各个变量
statement = null;
resultSet = null;
String strSql = null;
NoticeBean bean = null;
String title = null;
String content= null;try
{
title = "标题";
content = "内容";strSql = "INSERT INTO notice(title,content) values('"+title+"','"+content+"')";
statement = connection.createStatement();
statement.executeUpdate(strSql);
System.out.println("插入语句执行成功:" + strSql);
}
catch(SQLException ex1)
{
System.err.println("插入失败");
}
}
catch(Exception ex)
{
System.err.println(ex.getMessage());
}
}}控制台显示正常,打印如下:连接数据库成功
插入语句执行成功:INSERT INTO notice(title,content) values('标题','内容')可是进入mysql数据库里面看却是乱码,还有mysql里面后缀名为frm的是什么文件,是数据文件吗?怎么打开啊!oracle创建的数据文件好像就可以直接打开啊! 

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【zr_dixuexiongying】截止到2008-07-24 19:19:08的历史汇总数据(不包括此帖):
    发帖的总数量:101                      发帖的总分数:2260                     每贴平均分数:22                       
    回帖的总数量:186                      得分贴总数量:55                       回帖的得分率:29%                      
    结贴的总数量:98                       结贴的总分数:2200                     
    无满意结贴数:9                        无满意结贴分:170                      
    未结的帖子数:3                        未结的总分数:60                       
    结贴的百分比:97.03 %               结分的百分比:97.35 %                  
    无满意结贴率:9.18  %               无满意结分率:7.73  %                  
    值得尊敬
      

  2.   

    存入数据库时用:  
    把数据转成GBK的格式  
    name=new String(name.getBytes("gb2312"),"GBK");  
    content=new String(content.getBytes("gb2312"),"GBK");  
    从数据库取的时候用:  
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost/gfqqqqpe?
    user=gfqqqqpe_f&password=aaaaa&useUnicode=true;characterEncoding=GBK");  
    从数据库取的时候指定编码方式为"GBK",  
    然后显示的时候进行转换:  
    name=new String(name.getBytes("8859_1"),"GBK");  
    这种方法在MYSQL上通用
      

  3.   

    name=new String(name.getBytes("8859_1"),"GBK");