Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / June 2004

Tip: Looking for answers? Try searching our database.

ResultSets, and getting their size

Thread view: 
james - 22 Jun 2004 16:03 GMT
I have a resultset that is returned from a query, and i don't know the
amount of columns it has in it.  Does anyone know of a way i can get
all the data out of a record without knowing the exact amount of
columns??  Thanks.

j
Chris Smith - 22 Jun 2004 16:26 GMT
> I have a resultset that is returned from a query, and i don't know the
> amount of columns it has in it.  Does anyone know of a way i can get
> all the data out of a record without knowing the exact amount of
> columns??  Thanks.

You can't, but you can get its ResultSetMetaData and find out the number
of columns in the ResultSet from there.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Real Gagnon - 22 Jun 2004 23:06 GMT
> I have a resultset that is returned from a query, and i don't know the
> amount of columns it has in it.  Does anyone know of a way i can get
> all the data out of a record without knowing the exact amount of
> columns??  Thanks.

ResultSet rs = statement.executeQuery("select col1,col2,col3 from
mytable");

java.sql.ResultSetMetaData rsmd = rs.getMetaData();
int colNo = rsmd.getColumnCount();
while(rs.next()){
Object[] objects = new Object[colNo];
for(int i=0;i<colNo;i++){
  objects[i]=rs.getObject(i+1);
  }
}

Signature

Real Gagnon  from  Quebec, Canada
* Looking for Java or PB snippets ? Visit Real's How-to  
* http://www.rgagnon.com/howto.html

james - 23 Jun 2004 17:05 GMT
thanks everyone for the help.  I dug around on my own and found the
metadata piece and got it working.  Find it weird that they make you
get info from an onject through another object, but i assume that is
how they do...  Interesting enough.  Thanks for the quick and helpful
results.

j


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.