私はすでに Java でこのデータベースのポーリングを実装しており、outgoingqueue にあるすべての着信データを読み取ります。ポーリングされた行を更新する際に問題が発生しました。これは、行のいくつかの値を変更しただけのようなものです。
私の質問は:
1. ACTION=804 の値を持ち、最高の SEQ 値を持つように、このテーブルの行をループする方法。
2.以下のテーブルの KEYINFO1 と KEYINFO2 の値を変更するだけで行を更新する方法。
http://imageshack.us/photo/my-images/24/updatinganamolies.png/
ポーリングを行い、新しい着信メッセージをチェックするコードは次のとおりです
public void run() { // run method calls the fullpoll()
int seqId = 0;
while(true) {
List<KamMessage> list = null;
try {
list = fullPoll(seqId);
if (!list.isEmpty()) {
seqId = list.get(0).getSequence();
incomingQueue.addAll(list);
this.outgoingQueue = incomingQueue;
System.out.println("waiting 3 seconds");
System.out.println("new incoming message");
Thread.sleep(3000);
MessageProcessor processor = new MessageProcessor() {
@Override
public void run() {
generate(dbConnection);
}
};
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
public List<KamMessage> fullPoll(int lastSeq) throws Exception {
Statement st = dbConnection.createStatement();
ResultSet rs = st.executeQuery("select * from msg_new_to_bde where ACTION = 804 and
SEQ >" + lastSeq + "order by SEQ DESC");
List<KamMessage> pojoCol = new ArrayList<KamMessage>();
try {
while (rs.next()) {
KpiMessage filedClass = convertRecordsetToPojo(rs);
pojoCol.add(filedClass);
}
for (KpiMessage pojoClass : pojoCol) {
System.out.print(" " + pojoClass.getSequence());
System.out.print(" " + pojoClass.getTableName());
System.out.print(" " + pojoClass.getAction());
System.out.print(" " + pojoClass.getKeyInfo1());
System.out.print(" " + pojoClass.getKeyInfo2());
System.out.println(" " + pojoClass.getEntryTime());
}
} finally {
rs.close();
st.close();
// TODO: handle exception
}
したがって、これは行の生成に使用しているコード例ですが、最も高い SEQ および ACTION 値 = 804 という条件を設定してこの行を更新する方法です。
public void generate()
{
KpiMsg804 upd= createKpiMsg804();
while(true){
try {
st = conn.createStatement();
System.out.println("Updating Values");
String query = "insert into
msg_new_to_bde(tablename,action,keyinfo1,keyinfo2) values(?, ?, ?, ?)";
pstmt = conn.prepareStatement(query); // create a statement
pstmt.setString(1,upd.getTableName());
pstmt.setInt(2,upd.getAction()); // set value of action
pstmt.setString(3,upd.getKeyInfo1()); // set key-info value1
pstmt.setString(4,upd.getKeyInfo2()); // set key-info value2
int rows = pstmt.executeUpdate();
System.out.println("Number of Rows Created " +rows);
// execute insert statement
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public KpiMsg804 createKpiMsg804()
{
KpiMsg804 msg= new KpiMsg804();
msg.setKeyInfo1("ENTITYKEY2");
msg.setKeyInfo2("STATUSKEY2");
return msg;
}
ENTITYKEY と STATUSKEY を ENTITYKEY1 と STATUSKEY1 に変更して、行のテーブル内の 2 つの値を順番に変更するだけで更新する方法
メソッドが最大のシーケンス番号と対応する ACTIONKEY を持つ行を検索し、最終的に別の値を持つ行を更新 (値を変更) するようなロジックを使用する必要があります。
PS : 「お願い : 否定的な評価を付ける理由を教えてください (親指を下に向けてください)。私の質問を明確に説明できるように」