編集:oops。これらのJDBCステートメントは機能します。私はSQL Plusでコミットするのを忘れていました。ありがとうポール。JDBC ResultSet集計関数
私はSQL Plusでデータベースを照会:
select count(tid) from retweets where tid = 35 => 2
select count(tid) from tweets where replyto = 35 => 1
私は、データベースからJDBCを介してこれらの集計カウントを引くために、いくつかの方法を試してみました が、すべてのケースで、彼らは0
を返されました例:
Statement stmt = m_con.createStatement();
ResultSet retweets = stmt.executeQuery("select count(tid) from retweets where tid = 35");
if (retweets.next()) { System.out.println("# of Retweets: " + retweets.getInt(1));}
ResultSet replies = stmt.executeQuery("select count(tid) Replies from tweets where replyto = "+tid);
if (replies.next()) {System.out.println("# of Replies : " + replies.getInt("Replies"));}
両方とも0が印刷されました。なぜこのようなことが起こりましたか、どのように修正できますか?ありがとう。
嫌なことはありませんが、リツイートやつぶやきに35に対応するレコードがありますか? – gangreen
私は最初の型(getInt(1)付き)を文字通り何百回もやったことがあり、常に動作します。プログラムとSQL * Plusで同じデータベースを使用しているようなことは、あなたが私たちに言っていないこととは違うことがありますか? –