解压版mysql5+tomcat5+jsp乱码解决

主要是下载了解压版的MYSQL5.引起了以下问题.
1.为方便,在c:/myslq/bin下建了批处理文件.start.bat
--------
mysqld-nt remove
mysqld-nt -install
net start mysql
----------
和shutdown.bat
-------------
net stop mysql
------------------
2.启动后.在dos环境下,用mysql --default-character-set=gbk -u root -p ,录入密码进入mysql
 
3.create database if not exists `blog`;
USE `blog`;
/*Table structure for table `t_department` */
drop table if exists `t_department`;
CREATE TABLE `t_department` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `deptname` varchar(50) NOT NULL,
  `superior` bigint(20) default NULL,
  `description` varchar(600) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM default character set gbk;
/*Data for the table `t_department` */
insert into `t_department` values (1,'第一条',0,NULL),(2,'a2',1,NULL),(4,'aaa',0,NULL),(5,'bbb',1,NULL),(6,'ccc',1,NULL),(7,'dddd',1,NULL),(8,'eeee',1,NULL),(9,'ffff',1,NULL),(10,'gggg',1,NULL),(11,'hhhh',1,NULL),(12,'iiii',1,NULL),(13,'jjj',1,NULL),(14,'kkkk',1,NULL),(15,'lll',1,NULL),(16,'mmmm',1,NULL),(17,'nnnn',1,NULL),(18,'ooooo',1,NULL),(19,'pppp',1,NULL),(20,'qqqqq',1,NULL),(21,'rrrr',1,NULL),(22,'ssss',1,NULL),(23,'tttt',1,NULL),(24,'uuuu',1,NULL),(25,'vvvvv',1,NULL),(26,'wwww',1,NULL),(27,'yyyyy',1,NULL),(28,'zzzzz',1,NULL),(29,'abc',1,NULL),(30,'abcd',1,NULL),(31,'a3',1,NULL),(32,'a4',1,NULL),(33,'aaa',1,NULL);
/*注:上面结构是导出的.仅供参考**/
4.SERVER.XML文件连接数据库部分 
  <parameter>
      <name>url</name>
      <value>jdbc:mysql://localhost:3306/reportDB?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=GBK</value>
    </parameter>
5.jSP页面几个关键点.注:这个没有用STRUTS.主要是在便于在服务器上直接改.嘿嘿.
<%@ page contentType="text/html; charset=GB2312" %>
<%@page import="web.tools.PublicClass"%>
<%@page import="web.dbutil.ResultGatherPro"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Map"%>
<% request.setCharacterEncoding("GB2312"); %>
<html>

....
String deptname=request.getParameter("deptname");
System.out.println(deptname);
 
String sql ="select * from t_department  Where  "+sql_where+" limit "+(pagenum-1)*pagesize+","+pagesize+";";//分页.简单了一点.效率不快.
String sqlcount ="select count(*) as allrow from t_department Where  "+sql_where+";";
   ResultGatherPro rsa = new ResultGatherPro(sql,pagesize,pagenum,sqlcount);
    list=rsa.selectRS();
       int intListSize=list.size();
       session.setAttribute("pagenum",String.valueOf(pagenum));

 <td class="table-danyuange"><%=((Map)list.get(i)).get("deptname").toString()%></td>
直接取来显示.不用转码.这点比较好.哈哈.
贴图:
另:上面这个测试成功.没有问题.不过MYSQL客户端软件要选好.以免客户端显示乱码会影响到到开发效率...:)
再另:
听说有配置MY.INI文件的
[client]
port  = 3306
socket  = c:/mysql/mysql.sock
default-character-set = gbk
[mysqld]
port  = 3306
socket  = c:/mysql/mysql.sock
skip-locking
key_buffer = 256M
max_allowed_packet = 1M
table_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
default-character-set = gbk
这样后起动后变量为.
character_set_server = gb2312
character_set_system  = utf8
character_set_database =gb2312
character_set_client = gb2312
character_set_connection =gb2312
怎么样把 character_set_system     utf8  改为 gb2312?有人知道望回贴.
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭