日期:2014-05-20 浏览次数:20754 次
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3341/hibernate3.3.2?useUnicode=true&characterEncoding=utf8", "root", "sa");
statement= connection.createStatement();
String sql = "insert into User(UserId,Password, RecId) values('中国','123',126453)";
statement.executeQuery("set names 'utf8'");
statement.executeUpdate(sql);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}finally{
try {
if (rs != null) {
rs.close();
rs = null;
}
if (statement != null) {
statement.close();
statement = null;
}
if (connection != null) {
connection.close();
connection = null;
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
jdbc\:mysql\://localhost\:3306/house_manage?useUnicode\=true&characterEncoding\=utf-8