Link to home
Start Free TrialLog in
Avatar of dbeayon
dbeayon

asked on

Iterate through db2 field names

In Java 1.6, currently I am hard coding the field values that exist in a db2 table in a Is there a method that will allow me to connect to the db2 table and iterate through the current field names?



Avatar of dbeayon
dbeayon

ASKER

here is the code that I am using to grab the table info
I should be able to iterate through rsInput and list the column names.  Just not sure how at this point

	protected void createRSInput_new() throws Exception
	{
		
		String sql 	= "	Select * from " + TblInput 
					+ " Where DB2Recid = " + iDB2RecId;					
		
		Statement stmt = this.connJob.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
		rsInput = stmt.executeQuery( sql);
		
		if( rsInput == null || rsInput.absolute(1) == false)
		{
			System.out.println(sql);
			throw new Exception("Input record not found.");
			}
		return;
		}
	

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dbeayon
dbeayon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kent Olsen
Hi dbeayon,

I missed your question as I was literally "out to lunch".  :)

Your solution should work fine and is generic enough that it should work with just about and database.  If you need extended information from DB2 about a column (or even the column list) you can query the SYSIBM.TABLES view and interrogate the results.

  SELECT * FROM SYSIBM.TABLES where table_name = 'MYTABLE';   -- Note, tables are usually in UPPER case.


Good Luck,
Kent