getString() does not work for alias column name

Hi,

I need to use alias colum name as a parameter to resultset.getString().

But while doing so, I get the error "Invalid column name".

I get the alias name as colmnLabel. But not able to pass it as a parameter to getString().

I am using jconn3.jar and sybase version is 12.5.

Please suggest some way to achieve this.

Thanks,

Vishakha

[384 byte] By [jewlikara] at [2007-11-26 19:12:11]
# 1

PS's basic code pattern for fetching stuff out of a result set.

public class DBExample

{

public void fetch()

{

ResultSet resultSet = someMeansToGetAResultSet() ;

ResultSetMetaData metaData ;

HashMap map = new HashMap() ;

ArrayList list = new ArrayList() ;

if(resultSet != null)

{

metaData = resultSet.getMetaData() ;

while( resultSet.next() )

{

for(int i=1; i<=metaData.getColumnCount(); i++)

{

map = new HashMap() ;

map.put(metaData.getColumnName(i), resultSet.getObject(i)) ;

list.add(map) ;

}

}

}

// Don't forget to close out the db resources before you leave the method

}

}

Obviously there's no exception handling, or anything about getting the connection or result set, the point is about fetching the values out of the result set and putting them someplace more manageable and portable than a result set.

This is certainly not the only way to do this, but it is an easy to use pattern that works in a tidy manner.

Point being, don't assume you KNOW what the column name is. The result set metadata will definitely know.

Hope this helps,

PS.

puckstopper31a at 2007-7-9 21:10:26 > top of Java-index,Java Essentials,Java Programming...