jdbc连接mysql数据库乱码等

String url = "jdbc:mysql://10.0.1.123:3306/cadmin_hucheng?autoReconnect=true&useUnicode=true&characterEncoding=utf-8";

String userName = "root";

String password = "hskj2015";

String driver = "com.mysql.jdbc.Driver";

try {

Class.forName(driver);

Connection conn = DriverManager.getConnection(url, userName, password);

PreparedStatement p = conn.prepareStatement("insert into stu(name) values('测试》》》')");

p.executeUpdate();

p.close();

conn.close();

System.out.println(">>>>>>结束");

} catch (Exception e) {

throw new ExceptionInInitializerError(e);

}

猜你喜欢

转载自mr-lili-1986-163-com.iteye.com/blog/2370432