Standard Steps to Develop JDBC Application

Published: 21 July 2018
on channel: Code With Rohini
591
24

To learn Angular2 from scratch and most useful for beginners Please see the link below:
   • What is AngularJS and What is Angular...  

This video actually shows what JDBC does and how to develop JDBC application by using these standard steps.
Basic Components of JDBC:-
1. Driver:
It is a translator to convert Java calls into Specific Database calls and Specific Database calls
into Java calls.
2. Connection :
To convert these calls(Java and DB calls) some connection must be required and that is
nothing but Connection. In short, From Java Application to reach Database Connection must
be required.
3. Statement:
Its purpose is to send SQL Query to the DB under to bring the results from DB to Java
Application.
4. ResultSet:
It's nothing but set of Results processed in DB.
From this ResultSet Java Application can get the result of SQL Query.

*Standard Steps To Develop JDBC Application*
1.Load and Register Driver class.
-Syntax: Class.forName(“Driver Class Name”);
2. Establish Connection Between Java Application and Database.
Syntax:
Connection con=DriverManager.getConnection(“jdbc_url”,”user”,”pwd”);
3. Create Statement Object.
Syntax: Statement st=con.createStatement();
4. Send and Execute SQL Query and Stored in Resultset.
-Syntax: ResultSet rs=st.executeQuery(“select * from Employees”);
5. Process Result From ResultSet.
while(rs.next)
{
Syntax: System.out.println(rs.getInt(1)+” ”+rs.getString(2)+” ”+rs.getString(3));
}
Where rs.getInt(1) is the method contains first column of Employee table and its type is integer.
Ex.eno is type Int.
And same for String Type column 2 & 3 it may be ename & eadd.
6. Close the Connection.
Syntax: con.close();

**A Simple Java(JDBC) Program Using these Standard Steps:***

import java.sql.*; // package for SQL classes
public class JdbcDriver {
public static void main(String[] args) throws Exception {
// Step1:
Class.forName(“oracle.jdbc.OracleDriver”);
// Step2:
Connection con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:XE”,”root”,”apple”);
//Step 3:
Statement st=con.createStatement();
// Step 4 & 5:
ResultSet rs=st.executeQuery(select * from Employees);
while(rs.next)
{
System.out.println(rs.getInt(1)+” ”+rs.getString(2)+’’ ”+rs.getString(3));
}
// Step 6:
con.close();
} //closing of main method
} // closing of class

Note: In this program ,we are using Type 4 Driver i.e We are loading Type 4 Driver.

Conclusion:
In these steps, Connection, DriverManager, Statement, ResultSet are the classes which are
present in java.sql.*; package.
So by using these Standard Steps We can Develop any JDBC Application.


Watch video Standard Steps to Develop JDBC Application online without registration, duration hours minute second in high quality. This video was added by user Code With Rohini 21 July 2018, don't forget to share it with your friends and acquaintances, it has been viewed on our site 591 once and liked it 24 people.