JDBC IST 411 Lecture 4 Spring 2004 Vectors
JDBC IST 411 Lecture 4 Spring 2004
Vectors § One limitation of regular arrays is that their lengths remain fixed § Vector class § Contains methods for storing and retrieving objects § Access objects by their index position within the Vector § java. util. Vector class
Vectors § Vector is less efficient than an array in terms of processing speed § Flexibility to grow the data structure as needed § Vectors store objects not primitive data types like int
Vectors § Simple vector program.
JDBC § Present the Result. Set in a graphic interface to the user § JTable class in the javax. swing package is the tool of choice § A Result. Set object can be translated into a Vector of Vectors § Each row in the Result. Set is turned into a Vector by adding all of the fields to a vector § Then all of the row Vectors can be added to another Vector § JTable objects have rows, each mapped to a row Vector § Columns in the select clause become columns in the JTable
JDBC § JTable § Basic technique takes a pair of vectors, one for the headings for the database table and one for the data § Build a table from them JTable data. Table = new JTable (data. Vector, head. Vector)
JDBC § Resulting table can be much larger than one screen § Place the JTable inside another object JScroll. Pane data. Table. Scroll. Pane = new JScroll. Pane( ); data. Table. Scroll. Pane. set. Viewport. View(data. Table);
Abstract. Table. Model
JDBC § Every table gets its data from an object that implements the Table. Model interface. § Generally, you implement your table model in a subclass of the Abstract. Table. Model class. Model Table. Model View JTable
JDBC § Abstract. Table. Model class is in the javax. swing. table. * package § Look at Result. Set. Table. Model program § This example does not support editing the JTable cells
- Slides: 10