我希望能够从任何输入列查找并显示数据,但是我不知道如何将光标移动到右行。
这是我的代码,我知道 getRow 行是错误的。
ResultSetMetaData metadata = rs.getMetaData();
int colIndex;
int rowIndex;
rs = stmt.executeQuery("select COMPANY_CD from ARCUS where CUSTOMER_NO = '"+customer+"'");
rowIndex = rs.getRow();
rs.absolute(rowIndex);
colIndex = rs.findColumn("COMPANY_CD");
System.out.println(colIndex);
rowPane.add(new JLabel(metadata.getColumnName(colIndex)));
rowPane.add(new JLabel(rs.getObject(colIndex).toString()));
您可以前进或后退或到最后一个之前或第一个之前
//Move cursor forward
while (resultSet.next()) {
// Get data at cursor
String s = resultSet.getString(1);
}
// Move cursor backward
while (resultSet.previous()) {
// Get data at cursor
String s = resultSet.getString(1);
}
// Move cursor before first record
resultSet.beforeFirst();
这就是我解决类似问题的方法: rs.absolute(integer) 将光标移动到整数指定的行号 rs.relative(integer) 会将光标相对于当前位置移动整数
请务必指定光标为 SCROLL_INSENSITVE
祝你好运
PreparedStatement pstmt;
pstmt = myConn.prepareStatement("Select * from log limit 55", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = pstmt.executeQuery();
int counter = 0;
for (int i = 0; i < 6; i++) {
rs.absolute(i * 10);
counter = 0;
while (rs.next()) {
received = rs.getString("log_received");
callsign = rs.getString("log_callsign");
duration = rs.getString("log_duration");
迭代结果以获得目标行,然后结束循环
int rowIndex;
while (yourResultSet.next()) {
if(checkRowIsValid(yourResultSet)){
rowIndex = yourResultSet.getRow();
break;
}
}