myeclipse8.5+sqlserver2005+tomcat6.0,为什么添加到数据库中的汉字乱码?
#***************SqlServer2005数据库配置***************#
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://192.168.12.56:1433;DatabaseName=kjglxt
public int executeInsert(String sql) {
int num = 0;
try {
conn = DriverManager.getConnection(url, userName, password);
stmt = conn.createStatement();
num = stmt.executeUpdate(sql);
} catch (SQLException ex) {
System.out.println("执行错误SQL:" + sql);
System.err.println("执行插入有错误:" + ex.getMessage());
ex.printStackTrace();
} finally {
CloseDataBase();
}
return num;
}
跟踪到这里stmt.executeUpdate(sql);中的汉字还不是乱码,但执行后在数据库里查看就是乱码。将乱码改成汉字后,再显示到页面上就是正确的汉字。
谁遇到过这种情况,告诉我怎么办。谢谢!