易截截图软件、单文件、免安装、纯绿色、仅160KB

Hibernate插入mysql数据库中文乱码解决


使用ant工具编译程序,运行程序.命令:ant -f xxx.xml指定生成文件;ant run编译并运行文件。
如果Hibernate将中文插入mysql数据库,调用select语句中文显示乱码,则mysql的编码方式设为gbk,注意这里是小写,不用重新安装mysql数据库,将MySQL Server 5.1目录下的my.ini配置文件里的所有default-character-set设为gbk,注意小写,即可。
同时自己创建hibernate数据库时要设定数据库的默认编码方式:
create database hibernate default charset=gbk;
这样仍不行,考虑设定hibernate数据库中表的默认编码方式。(很重要)另外,在java源代码中n.setTitle("你好吗");之前也可添加转码语句,根据情况而定,这里可有可无。
String na="";
    try{
        na="疯狂联盟成立了";
        byte bb[]=na.getBytes("GBK");
        na=new String(bb);
       }catch(UnsupportedEncodingException ex){
       throw new RuntimeException("unsupported encoding type.");
     }
然后在hibernate.cfg.xml属性文件里添加
<property name="connection.useUnicode">true</property>
  <property name="connection.characterEncoding">UTF-8</property>
中文乱码问题解决,一切OK。
这里UTF-8也可为GB2312,GBK。
注意要添加import java.io.*;


相关文档:

实践经验汇集成的MySQL应用指南


 
【书名】高性能MySQL(第二版)
【原书名】High Performance MySQL, second edition
【作者】Baron Schwartz,Peter Zaitsev,Vadim
Tkachenko,Jeremy D.Zawodny,Arjen Lentz,Derek
J.Balling  著
【译者】王小东 李军 康建勋 译
【出版社】电子工业出版社     
【书号】978- ......

Java+Mysql的数据库查找实现


public class select {
 public List XiuGai_select(String keyword){
  List list=new ArrayList();
        Connection conn = null;
  Statement stmt = null;
  String sql=null;
  ResultSet res = null;
  get ......

mysql的三种安装方式

安装的OS为Solaris10,mysql 版本是5.1.38
一、使用RPM包进行安装

    首先可以从安装光盘中或者到mysql的网站上下载对应版本的rpm包如下:
MySQL-server-community-5.1.38-0.rhel5.i386.rpm
MySQL-client-community-5.1.38-0.rhel5.i386.rpm
    接着我们可以使用rpm命 ......

mysql中插入一条记录返回该记录id

1.select max(id) from user;
2.select last_insert_id() as id from user limit 1; 
(这个测试的返回id一直是0,有点问题)
3.储存过程
1)
oracel中
create sequence seqID
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
nocache
order;
create or replace procedure ......

mysql中的union和order by、limit

我有一个表
CREATE TABLE `test1` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `desc` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
(1)以下查询会报错误:[Err] 1221 - Incorrect usage of UNION and ORDE ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号