求救,用jdbc插入数据的时候,中文出现乱码如何解决?
我使用的数据库是MYSQL,我的代码如下:
import java.sql.*;
public class InsMySQL {
public static void main(String agrs[]) {
String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:mysql://localhost:3306/jxgl";
String user = "sb";
String password = "songbo";
try {
Class.forName(driver);
}
catch(Exception e) {
System.out.println("无法加载驱动程序:" + driver);
}
try {
Connection conn = DriverManager.getConnection(url,user,password);
if(!conn.isClosed())
System.out.println("数据库连接成功!");
Statement smt = conn.createStatement();
smt.executeUpdate("INSERT into teacher(t_no,t_name,t_sex,t_birthday,tech_title)" +
"values('000011','张燕,'女','1967-06-06','讲师')");
System.out.println("记录插入完毕!");
smt.close();
conn.close();
}
catch(SQLException ee) {
System.out.println("数据库连接失败!");
}
}
}