qq_37198503
qq_37198503
采纳率8.3%
2017-07-12 11:02 阅读 444

java连接新浪SAEmysql数据库超时

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(ps!=null){
        ps.close();
        if(connection!=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);
    }
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐