
/* This is a sample program for executing simple queries through JDBC.
 * Replace mylogin & mypassword by your login & password respectively.
 */ 

import java.sql.*;

public class simpleExecute {
	public static void main( String[] args ) throws SQLException {
		Connection con = null;
		Statement stmt = 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:@everest:1521:GEN", "mylogin","mypassword");

			stmt = con.createStatement();
			rs = stmt.executeQuery( "SELECT sno, sname FROM dbis.supplier");

			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()) {
				int no = rs.getInt("SNO");
				String name = rs.getString("SNAME");
				System.out.println( no + "\t" + name);
			}
		} catch(SQLException sqle){
			System.out.println("Exception " + sqle);
		}
	}
}
