users@glassfish.java.net

Helpful SQLTable

From: <glassfish_at_javadesktop.org>
Date: Thu, 08 May 2008 15:23:35 PDT

Thsi is a basic code to help with sql results.

it stores it into an array that contains treemaps. so u can do stuff like

mytable.getTable().get(i).get("sku")

i prob will expand my file to also be able to have a treemap be able to be inserted into a mysql row for quicker ways of managing data.

[code]
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ottoclass;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.TreeMap;
import java.util.Vector;

/**
 *
 * @author dlee
 */
public class SQLTable {

    private Vector<TreeMap> vectortable = new Vector<TreeMap>();

    public SQLTable()
    {
        
    }

    public Boolean makeTable(ResultSet myresult) throws SQLException
    {
        vectortable = new Vector<TreeMap>();
        int i = 0;
        
        try
        {
            while (myresult.next())
            {
                TreeMap table = new TreeMap();
                for (int j = 1; j <= myresult.getMetaData().getColumnCount(); j++)
                   table.put(myresult.getMetaData().getColumnLabel(j), myresult.getObject(j));
                
                vectortable.add(table);
                
                i++;
            }
        }
        catch (SQLException e)
        {
            throw e;
        }

        return (i != 0);
    }
    
    public Vector<TreeMap> getTable()
    {
        return vectortable;
    }
    
    public TreeMap getRow()
    {
        return vectortable.get(0);
    }
    
    public Object getCell(String filename)
    {
       return vectortable.get(0).get(filename);
    }

}

[code]
[Message sent by forum member 'flyingbuzz' (flyingbuzz)]

http://forums.java.net/jive/thread.jspa?messageID=273420