易截截图软件、单文件、免安装、纯绿色、仅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小数位取整

//得分计算四舍五入
SELECT ROUND((SUM(getfeng)/SUM(totalfeng))*100) as feng from answerdata WHERE uid='151' AND targetid IS NOT NULL
1.ceil () /ceiling() 向上取整
   例: ceil(1.2) = 2
2.floor () 向下取整
    例: floor(1.2) = 1
3.round() 四舍五入
 &n ......

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中的正则表达式搜索

语法:
select * from table_name where column_name regexp '正则表达式'
或区分大小写
select * from table_name where column_name regexp binary '正则表达式'
支持的正则表达式符号:
.    任意字符
|    或,如:a|b|c
[]   范围,比如:[a-z],[0-9],[^0-9]不包 ......

jsp连接mysql对数据库进行操作乱码的解决


如果jsp插入mysql数据库出现乱码,mysql数据库安装时编码设为utf8,在执行插入语句的前面(紧挨着执行语句)添加转码语句:String na="";
                  try{
          &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号