java连接新浪SAE的mysql数据库超时

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);
    }
}

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐