Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

JDBC

It helps users to  interact (or) communication with various database. 


JDBC is an API(Application programming Interface). 
TYPES : 
1. Two-tier Model. 
2. Three-tier Model. 
1.Two-tier Model 
Java application  directly communicate with database . 
JDBC driver provides communicate java application  with data source. 
 
2. Three-tier Model 
Commands are sent to “middle tier ” of service , which then sends the commands to data
source. The data  source process the command , sends the results back to middle tier and then it
sends them to user. 
 
 
STEPS TO CONNECT THE JDBC  
1. Import packages. 
2. Load Drivers.   
3. Create Connection.  
4. Create Statement. 
5. Execute the queries. 
6. Retrieving the results. 
7. Close the Connection. 
 
 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.ResultSet; 
import java.sql.Statement; 
 
public class Connect  

 
public static void main(String[] args)  

 
try { 
Class.forName("com.mysql.jdbc.Driver"); 
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/
ovs","root","19L239@kce"); 
Statement statement=connection.createStatement();
 
// delivery the executed records 
 
ResultSet resultSet=statement.executeQuery("SELECT * FROM POSNAME"); 
while(resultSet.next()) 
 
System.out.println(resultSet.getString(1) +"  "+resultSet.getString(2) +" "+ "
"+resultSet.getString(3)); 
 
statement.close(); 
connection.close(); 
 

catch (Exception e) 

System.out.println(e); 

 
 
 

 

 
 

You might also like