こんにちは、基本的な Storm アプリケーションをセットアップして、ツイートのストリームを受信し、MySQL データベースに保存します。アプリケーションは、最初の ~ 23 時間ほどは問題なく動作し、その後、次のエラーが発生し始めます。
SQL Exception
SQL State: 08003
これを数回行うと、死にます。標準の JBDC コネクタを使用して、Java からデータベースに接続しています。DB接続を保存および設定するための関数のコードは次のとおりです。
private String _db="";
private Connection conn = null;
private PreparedStatement pst = null;
public ArchiveBolt(String db){
_db = db;
}
private void setupConnection() {
//Connect to the database
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:8889/twitter_recording", "root", "root");
} catch (Exception e){
e.printStackTrace();
}
}
public void execute(Tuple tuple, BasicOutputCollector collector) {
Status s = (Status) tuple.getValue(0);
//setup the connection on the first run through or if the connection got closed down
try {
setupConnection();
} catch (Exception e) {
// TODO: handle exception
System.out.println(e.toString());
}
try {
pst = conn.prepareStatement("INSERT INTO " + _db + " (tweet)" +
"VALUES (?);");
pst.setString(1, s.toString());
//execute the SQL
pst.executeUpdate();
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
if(ex.getSQLState().equals("08003")){
setupConnection();
}
} finally {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
08003 エラーが原因でクラッシュしていることが明らかになった後、そのエラーがスローされた場合は、接続のセットアップを再試行する必要があると判断しましたが、それも役に立ちませんでした。この問題を解決するための正しい方向に私を向けることができますか?