Wednesday, July 13, 2011

JDBC Connection with Oracle 10g Express Edition

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JdbcConnection
{
    public static Connection createConnection()
    {
        Connection con=null;
        String driverName="oracle.jdbc.driver.OracleDriver";
        String url="jdbc:oracle:thin:@localhost:1521:XE";
        String user="system";
        String password="piyu";
       
       
        try
        {
            Class.forName(driverName);
            con=DriverManager.getConnection(url, user, password);
            if(con!=null)
            {
                System.out.println("Connection Success");
            }
            else {
                System.out.println("Connection  Not Success");
            }
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
       
       
        return con;
    }
    public static void main(String[] args)
    {
        JdbcConnection connection=new JdbcConnection();
        connection.createConnection();
    }
}

Note : This Program Require classes12.jar Just Go To www.java2s.com and download it..

No comments:

Post a Comment