qq_37198503
qq_37198503
采纳率8.3%
2017-07-13 01:53 阅读 778

Java连接新浪SAEmysql数据库超时

public Connection getConnection() {
Connection connection=null;
String url="jdbc:mysql://r.rdc.sae.sina.com.cn:3306/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条回答 默认 最新

  • oyljerry oyljerry 2017-07-13 03:07

    先看你用mysql客户端能不能连接上数据库。很可能网络问题

    点赞 评论 复制链接分享

相关推荐