Posts

Showing posts from February 15, 2011

Database connectivity in java using ODBC (Type 1 driver)

Image
There are 7 seven steps to connect simple java program to the database 1.Load the driver.    (     Class.forName( DRIVER NAME ); ) 2.Define the connection url.    (  String Url="jdbc:odbc:DSN"; ) 3.Establish the connection.    (  Connection con=DriverManager.getConnection(URL,Username,Password)) 4.Create the statement.    ( Statement stmt=con.createStatement();) 5.Execute the query.    String query ="SELECT col1, col2, col3 FROM sometable";    ResultSet resultSet =statement.executeQuery(query); 6.Process the result.     while(resultSet.next()) {        System.out.println(resultSet.getString(1) + " " +        resultSet.getString(2) + " " +   resultSet.getString(3));     } 7.Close the connection.      con.close(); Now a simple program import java.sql.*; class JDBC { JDBC()...