Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Iterate through db2 field names

Posted on 2009-02-16
3
Medium Priority
?
594 Views
Last Modified: 2012-05-06
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?



0
Comment
Question by:dbeayon
  • 2
3 Comments
 

Author Comment

by:dbeayon
ID: 23651765
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

0
 

Accepted Solution

by:
dbeayon earned 0 total points
ID: 23652075
this served my purpose
		ResultSetMetaData rsmd = rsInput.getMetaData();
		int colCount = rsmd.getColumnCount();
	      String colName, colType;
	      for (int i = 1 ; i <= colCount ; i++)
	      {
	        colName = rsmd.getColumnName(i);
	        colType = rsmd.getColumnTypeName(i);
	        addFldsFromInput( colName ); 
	        System.out.println(colName);
	      }

Open in new window

0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 23652289
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question