简体   繁体   中英

How to use Vector as DataSource?

I want to use this vector as DataSource for my Jtable. 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)

为此有一个模式名称: 值列表处理程序 ,是延迟加载的一种特定形式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM