How to use Vector as DataSource?
I want to use this vector as DataSource for my Jt开发者_如何学Pythonable. There are four columns here (ADI, SOYADI, BABA ADI, ANA ADI). ResultSet is adding every row to vector named _kisivector. This is my DataSource.
But I don't want to get whole records at start. I want to get only 5 records from this vector. Then there will be 2 button, back and forward. When I click Forward it will go for other 5 record. And when I click back button, it will go for 5 previous record.
Is there any example for this?
private Vector getSonuc(String _ad){
Vector _kisivektor = new Vector();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@xx.xx.xx.xx.:1521:xxxx", "xxx", "xxx");
stmt = conn.prepareStatement("select * from t_gnl_kisi where ADI like ?");
stmt.setString(1, _ad+"%");
rs = stmt.executeQuery();
while (rs.next()) {
_kisivektor.add(rs.getString("ADI"));
_kisivektor.add(rs.getString("SOYADI"));
_kisivektor.add(rs.getString("ANA_ADI"));
_kisivektor.add(rs.getString("BABA_ADI"));
}
stmt.close();
rs.close();
}
catch (Exception e) {
e.printStackTrace();
}
return _kisivektor;
}
}
You can use the solution discussed here, http://forums.sun.com/thread.jspa?threadID=5425845&tstart=1 (This is on demand fetching)
This is prefetching
http://forums.sun.com/thread.jspa?threadID=5371696
Finally if you want to get batch of data of 5 rows. You can subclass the Data Model and only read 5 rows and keep connection open. When "Back" or "Forward" buttons are pressed you can scroll the resultset to that many records (you anyway are going to have a twoway scrollable result set)
There is a pattern name for this: Value List Handler which is a specific form of Lazy Loading.
精彩评论