26 May 2004 - java_dev (original) (raw)

Java developers

May 26th, 2004

08:25 am - neophoenix - java.sql.ResultSet -> Vector I'm currently working on a test project (i.e. just to see if I can do it) that takes a ResultSet from one class, cycles through it to create a vector (technically a vector of vectors) and then uses the vector(s) to populate a JTable. It works fine but I've been looking for a more elegant way of building the vector - does anyone know of a more OOP-friendly way of accomplishing this? Right now I'm iterating through the ResultSet and adding each value to the vector. This seems to be kinda old-skool and not very effecient. Here's a code snippit (the important bits at least):/* * tableData is a ResultSet with 23 records inside. Each record has 12 fields/columns. * rowCount is an integer used to hold the total number of rows as 23 is not static. * colCount is an integer that was set in a different method which was build from the ResultSetMetaData. * row is a Vector which contains a single row * rowData is a vector which contains a collection of row vectors. */ tableData.last(); rowCount = tableData.getRow(); tableData.first(); System.out.println(rowCount); rowData = new Vector(rowCount); for(int x = 1; x <= rowCount; x++){ row = new Vector(colCount); for(int y = 1; y <= colCount; y++){ System.out.println("Row number " + x + " Column number " + y + " - Value = " + tableData.getString(y)); row.add(tableData.getString(y)); System.out.println("Column added to row"); } rowData.add(row.clone()); tableData.next(); } tableData.close(); I haven't tried it yet but I'm thinking that I might be able to recast the ResultSet into something a bit more generic. Either that or I can create a new class which extends ResultSet and add my own methods (getRowData(int x) or something).TIA!
12:45 pm - traceawaythefog Ok, I'm VERY new to this whole Java thing - so this is class related. I'd ask my teacher, but my teacher isn't so great at explaining things for some reason. I know this probably simple, but I would appreciate any and all help on this.Here's a little background info on it:( Read more...Collapse )I get it to work for one number, and then I get stuck.Here's a copy of the code for the one that I get to work:( Read more...Collapse ) If anyone can help me, I'll kiss the ground they walk on, no joke.