Using The JDBC Driver With Java Applications
//Title: Using JDBC
//Description: Given Java code queries the emp table to find the
// location of each employee package package1;
import Java.sql.*;
public class find_location
{
public static void main (String args[ ] )
throws SQLException
{
String cstring = args [ 0 ] ;
String uname = args [ 1 ] ;
String pwd = args [2];
// Load JDBC Drivers
try
{
Class.forName ("oracle.jdbc.driver.OracleDriver");
}
catch (ClassNotFoundException e)
{
System.out.println ("Unable to load driver");
}
// using the connection parameters connect to the database
Connection conn=DriverManager.getConnection (cstring, uname, pwd);
// create and store the employee locations
Statement stmt = conn.createStatement( ) ;
//Query and store the employee locations
//the output in the result set
ResultSet rset = stmt.executeQuery ("select empno, ename,city from emp");
while (rset.next( ) )
{
//Get Employee Number
int eno = rset.getInt (1);
//Get Employee Name
String ename = rset.getString (2);
// Get Employee city
double loc = rset.getString (3);
System.out.println (eno + " + ename +" " + city);
}
conn.close ( ) ;
}
}