0

Hello,

I have this piece of code.

private Vector getColumn(ResultSet rs)
	        throws SQLException
	        {
	            Vector row = null; 
	            ResultSetMetaData rsmd = null;
	            boolean moreResults = rs.next(); 
	            if (moreResults)
	            {
	            	row = new Vector();
	            	rsmd = rs.getMetaData();
	                do
	                {
	                	switch(rsmd.getColumnType(1))
	                	{
	                	case Types.VARCHAR:
	                		row.addElement(rs.getString(1));
	                		System.out.println(rs.getString(1));
	                		break;

	                	case Types.INTEGER:
	                		row.addElement(new Integer(rs.getInt(1)));
	                		System.out.println(rs.getString(1));
	                		break;

	                	
	                	case Types.FLOAT:
	                	row.addElement(new Float(rs.getFloat(1)));
	                		System.out.println(rs.getString(1));
	                		break;
	                		
	                	default:
	                		System.out.println("Column Type: " + rsmd.getColumnTypeName(1));
                	}
                }while(rs.next());
            }
            return row;
	        }

However, it will not catch the Float data type. I tried it with double, etc, but it will not work. The output that I get is the following:

select iID from items
101
102
103
104
select description from items
Watch
T-Shirt Collection
Heavy Duty Tea Cup
Shirts
select highestBid from items
Column Type: FLOAT
Column Type: FLOAT
Column Type: FLOAT
Column Type: FLOAT
Size of descArray: 4

Any suggestions on how to get the code to read data type Float?

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by masijade
0

Well I do not exactly whats wrong since you have not given us the table schema, but have you tried just printing the value returned by rsmd.getColumnType(1) .

Although just for the record I do not see why it should be different from one given by rsmd.getColumnTypeName(1)

0

Debug the code to find the actual type number returned and what it equates to. If you don't know how to use the debugger then print out the varying types at the top of the method as follows

System.out.println("Integer TYPE:  " + Types.INTEGER);
  System.out.println("Float     TYPE:  " + Types.FLOAT);
  ...

Then, just before the switch do

System.out.println(rsmd.getColumnType(1));

And see what that equates to.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.