JDBC
JAVA DSN Based Connectivity
Connection
public static void main(String[] args) { Connection conn = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ; // Connect with a url string conn = DriverManager.getConnection("jdbc:odbc:oracle","hr","hr"); String sqlQuery="select employee_id,last_name, first_name, job_id from employees"; Statement stmt = conn.createStatement(); ResultSet results =stmt.executeQuery(sqlQuery); System.out.println("Employeeid, lastName,firstName,JobID"); while( results.next()) { String employeeID= results.getInt("employee_id" )+ ""; String last_name= results.getString("last_name" ); String first_name= results.getString("first_name" ); String job_id= results.getString("job_id" ); System.out.println(employeeID+","+last_name+","+first_name+","+job_id); } } catch (Exception e) { System.err.println("Exception: "+e.getMessage()); }finally { if(conn!=null) { try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
Please send comments to
vgdarur.javafive@blogger.com
Copyright © 2008 - iForeRunner.com
http://www.iforerunner.com/