public Connection getConnection() {
Connection connection=null;
String url="jdbc:mysql://w.rdc.sae.sina.com.cn:3307/app_liuweiweixin";
String username="n5xky4z2k5";
String password="0h4j3y553my0yk3m121h3kxkhilh1k32xj333lhh";
try {
Class.forName("com.mysql.jdbc.Driver");
connection=DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
public void releaseResource(Connection connection,PreparedStatement ps){
try {
if(connection!=null){
ps.close();
if(ps!=null){
connection.close();
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void saveTextMessage(String openid,String connection){
MySQLUtil mysql=new MySQLUtil();
Connection conne=mysql.getConnection();
String sql="INSERT INTO message_text (open_id,content,create_time)VALUES (?,?,now()) ";
PreparedStatement ps=null;
try {
ps =conne.prepareStatement(sql);
ps.setString(1,openid);
ps.setString(2,connection);
ps.execute();
} catch (SQLException e) {
e.printStackTrace();
}finally{
mysql.releaseResource(conne,ps);
}
}