JDBC is java based API or technology to access data from database and use in Java Desktop or Enterprize application.
In short we can say JDBC is an interface between Java and Database, using JDBC you can interact with any of database as Oracle, MySQL, Access.
JDBC is released with JDK(Java Development Kit)1.1 on 19 Feb 1997 and It is a part of Java Standard Edition. if you know about DBMS(Database Management Systems) then you should know about Database Drivers, drivers are of 4 types.
JDK1.7- Download jdk1.7
Now we will learn that how to implement Database connection in Java. To start with JDBC you must have a little knowledge of DBMS and SQL(Structured Query Language) to interact with Database
here i will show you that how to connect with Oracle Database
Follow these steps to connect with Oracle Database
A. Using DriverManager class
The syntax is - DriverManager.registerDriver(DriverName);
B. Using Class.Forname class
The syntax is - Class.forName(”DriverName”);
Connection interface is inside java.sql package and extends Wrapper interface. now to create Connection we register driver with DriverManager class.
Syntax is- DriverManager.getConnection("url string", "username", "password");
You have to change url string with your ip address and SID according to your database setting
Now we see that how to execute SQL query using PreparedStatement and store its result in ResultSet object
Here i am getting username and password from LOGIN_DET table (you can use your own query here)
This is the brief overview of using JDBC with Oracle Database, For others you have to change only DriverName respectively
Happy Learning :)
JDBC is released with JDK(Java Development Kit)1.1 on 19 Feb 1997 and It is a part of Java Standard Edition. if you know about DBMS(Database Management Systems) then you should know about Database Drivers, drivers are of 4 types.
- Type 1 Driver - JDBC-ODBC bridge
- Type 2 Driver - Native-API Driver
- Type 3 Driver - Network-Protocol Driver(MiddleWare Driver)
- Type 4 Driver - Native-Protocol Driver(Pure Java Driver)-Thin Driver
JDK1.7- Download jdk1.7
Now we will learn that how to implement Database connection in Java. To start with JDBC you must have a little knowledge of DBMS and SQL(Structured Query Language) to interact with Database
here i will show you that how to connect with Oracle Database
Follow these steps to connect with Oracle Database
1. Load Driver (Thin Driver)
The very first step towards database connection is Loading Driver, as discussed we use pure java driver in JDBC connectivity there are two steps to load driver for connectionA. Using DriverManager class
The syntax is - DriverManager.registerDriver(DriverName);
- try {
- }
B. Using Class.Forname class
The syntax is - Class.forName(”DriverName”);
- try {
- }
2. Create Connection
Connection interface is inside java.sql package and extends Wrapper interface. now to create Connection we register driver with DriverManager class.
Syntax is- DriverManager.getConnection("url string", "username", "password");
- Connection con;
- try {
- "jdbc:oracle:thin:@192.168.1.234:1521:XE", "hr", "hr");
- }
You have to change url string with your ip address and SID according to your database setting
3. Execute PreparedStatement and return Resultset
Now we see that how to execute SQL query using PreparedStatement and store its result in ResultSet object
Here i am getting username and password from LOGIN_DET table (you can use your own query here)
- Connection con;
- try {
- jdbc:oracle:thin:@192.168.1.241:1521:eadf", "hr", "hr");
- if (rs.next()) {
- while (rs.next()) {
- + "and Password is-->" + rs.getString(2) +
- "Email Id is--->" + rs.getString("E_ID"));
- }
- }
- psmt.close();
- con.close();
- }
This is the brief overview of using JDBC with Oracle Database, For others you have to change only DriverName respectively
Happy Learning :)