This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Hashtable Problem
Posted by Naveen on May 02, 2001 at 6:44 PM
What I have been trying to do is define a class called SelectComponent and this class will be used by a servlet. The Hashtable will be used for different table values. This process is for Table Maintenance. Instead of creating separate servlets for different tables, I am trying to develop this process. I am also trying to put a Switch statement to process different data types. But, I am not sure about it. Please note that I am a bit new to Java programming. Declarations: public class SelectComponent { public int rowCount; public int columnCount; public int currentRow; private Hashtable records; private int value; } I was able to determine the solution to a certain extent by doing this: Hashtable[] records = new Hashtable[meta.getColumnCount()]; But, now there is a new error: "The method put invoked for type java.util.Hashtable with arguments (int, java.lang.String) is not defined." ---- at this line in the code: records[i].put(row, rs.getString(i+value)); Please find below the modified code. /** * SelectComponent constructor comment. */ public SelectComponent(Connection c, String sql) throws SQLException { try { Statement stmt= c.createStatement(); ResultSet rs = stmt.executeQuery(sql); ResultSetMetaData meta = rs.getMetaData(); meta.getColumnCount(); Hashtable[] records = new Hashtable[meta.getColumnCount()]; int row = 0; while (rs.next()) { row++; records[value] = new Hashtable(); for (int i = 0; i < columnCount; i++) { //Switch (mt.getDataType()) { //case double: //Records[i].put(row, rs.getDouble(i+value)); //break; //case int: //Records[i].put(row, rs.getInt(i+value)); //break; //case date: //Records[i].put(row, rs.getDate(i+value)); //default: records[i].put(row, rs.getString(i+value)); //break; //} } } setRowCount(row); } catch (Exception e) { e.printStackTrace(); } } Thank you, Naveen
Replies:
|