/* This is a sample program demonstrates the use of Prepared statement.
 * Replace mylogin & mypassword by your login & password respectively.
 */ 

import java.sql.*;

public class resultSetMetaData {
	public static void main( String[] args ) throws SQLException {
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		ResultSetMetaData rsmd = null;

		try {
			DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver());
			/* Please substitute mylogin, mypassword by your login 
			 * and password.
			 */
			con = DriverManager.getConnection( "jdbc:oracle:thin:@10.105.1.30:1521:oradb", "dbis","dbis");

			pstmt = con.prepareStatement( "select id, name from dbis.instructor where dept_name like ?" );
			pstmt.setString( 1, "Comp%" );
			rs = pstmt.executeQuery();

			rsmd = rs.getMetaData();

			for( int i = 1; i <= rsmd.getColumnCount(); i++ ) {
				System.out.print( rsmd.getColumnName(i)  + "\t" );
			}

			System.out.print( "\n" );

			while (rs.next()) {
				String no = rs.getString("id");
				String name = rs.getString("name");
				System.out.println( no + "\t" + name );
			}
		} catch(SQLException sqle){
			System.out.println("Exception " + sqle);
		}
	}
}
