我已经在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
来更新序列中表中的两个值来更新我必须使用一个逻辑,以便我的方法应该查找具有最高序列号和相应ACTIONKEY的行,最后它使用不同的值更新(更改值)行。
P.S:“请求:请给出给予否定分数的理由(大拇指向下)。这样我就能清楚地解释我的问题”