Steps to create a connection between Java Program and Oracle Database:-
***********************************************************
Step1:Create a DSN name
--> Control Panel
--> System and Security
--> Administrative Tools
--> ODBC data Source
--> select System DNS tab
--> Click on Add Button
--> Scroll Down and Select Microsoft ODBC for Oracle
--> click Finish Button
--> Microsoft ODBC for Oracle Setup will display
--> Give Data Source Name
--> and press OK
--> OK
--> Completed
************************************************************
Step2:Write a JDBC program
-> Open an Editor(notepad or EditPlus or NotePad++)
--> Write Code as written below
------------------------------------------------------------------------------------------------
import java.sql.*;
public class FirstJdbcProgram
{
public static void main(String[] args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//Load and Register the Driver
Connection con = DriverManager.getConnection("jdbc:odbc:ach","system","india");//Create Connection
if(con==null){
//DriverManager.getConnection() return null when DNS not exist or Wrong Database username and Password
System.out.println("Connection not Created");
}else{
System.out.println("Connection Created");
}
con.close();
}
}
************************************************************
*Note:
----------
1.While Writing "Class.forName "----C and N is Capital
"JdbcOdbcDriver"---J,O,and D is Capital
2.If you are facing difficulties while preparing DSN name in Windows8 or later version OS then
then try other Type of Driver Check Other post for Other type of Driver
Youtube Link:
http://youtu.be/Blfugth1Xeo
No comments:
Post a Comment