首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

mysql写入乱码有关问题,help

2013-07-09 
mysql写入乱码问题,help~本人用junit写了一个测试类,往mysql中写入数据。代码如下:spring配置文件:?xml ve

mysql写入乱码问题,help~
本人用junit写了一个测试类,往mysql中写入数据。代码如下:
spring配置文件:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans  
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd  
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<context:property-placeholder location="classpath:jdbc.properties" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${driverClassName}" />
<property name="jdbcUrl" value="${url}" />
<property name="user" value="${username}" />
<property name="password" value="${password}" />
</bean>

<bean id="dblog" class="com.essp.uas.dao.db.DBLog">
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>




driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/uas?useUnicode=true&amp;characterEncoding=utf-8
username=root
password=
initialSize=1
maxActive=10
maxIdle=2
minIdle=1



package com.essp.uas.test;

import java.sql.Types;

import javax.annotation.Resource;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.essp.uas.dao.ILog;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { "/applicationContext-db.xml" })
public class DBTestUnit {

@Resource
private ILog log;

@Before
public void init() {
}

@After
public void destory() {
}

@Test
public void testMidifyLdapAttrbute() {


Object[] args = new Object[] {
"137031112",
"门户",
"1365336825896",
"中文",
"2013-06-05 01:16:15",
"192.168.10.118",
"1370363952868",
"7C0307F32418DC717FE3777BE0C2ACB8",
"org,湖北省"
                };  
        int[] argstypes = new int[] {
        Types.VARCHAR,
        Types.VARCHAR,
        Types.VARCHAR,
        Types.VARCHAR,
        Types.VARCHAR,
        Types.VARCHAR,
        Types.VARCHAR,
        Types.VARCHAR,
        Types.VARCHAR
        };  

log.writelog(args, argstypes);
}

}



以上是java端的代码,可运行后写入mysql发现中文都是??
我的mysql字符集设置如下:
collation_connectionutf8_general_ci
collation_databaseutf8_general_ci
collation_serverutf8_general_ci
建表语句
`table_name` (
  `ID` varchar(20) CHARACTER SET utf8 NOT NULL DEFAULT '',
  `AppName` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
  `USERID` varchar(200) CHARACTER SET utf8 DEFAULT NULL,
  `USER_NAME` varchar(200) CHARACTER SET utf8 DEFAULT NULL,
  `CREATE_TIME` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
  `IP` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
  `APPID` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
  `TOKEN` varchar(200) CHARACTER SET utf8 DEFAULT NULL,
  `Department` varchar(60) CHARACTER SET utf8 DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

我能想到的所有地方都改为utf-8了,问题还是没解决。请教玩mysql的童鞋


[解决办法]
url=jdbc:mysql://localhost:3306/uas?useUnicode=true&amp;characterEncoding=utf-8
 这个错了把, 
url=jdbc:mysql://localhost:3306/uas?useUnicode=true&characterEncoding=utf-8
 应该是这样!

还有密码最好不要为空

热点排行