日期:2014-05-20  浏览次数:20683 次

mysql乱码问题
public class DB {

public static void main(String[] args) throws Exception {

Class.forName("com.mysql.jdbc.Driver");

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/hibernate","root","lixun");

Statement sm = conn.createStatement();

String sql = "insert into student values(40,'在',3)";
//ResultSet rs = 
sm.executeUpdate(sql);


//rs.close();
sm.close();
conn.close();
向mysql数据插入汉字时显示??,是怎么回事,数据库哪个地方有问题

------解决方案--------------------
jdbc:mysql://localhost:3306/hibernate在后面加?useUnicode=true&characterEncoding=utf8

第一次来回复,,才系统的学习几个月,,,,,,不知道对不对
------解决方案--------------------
首先看看你的数据库是什么编码,然后jdbc:mysql://localhost:3306/hibernate在后面加?useUnicode=true&characterEncoding=数据库编码

String sql = "insert into student values(40,'在'.getbyte(数据库编码),3)";