0% found this document useful (0 votes)
20 views2 pages

JDBC

JDBC is an API that allows Java applications to connect to databases. It supports both two-tier and three-tier architectures. To connect using JDBC, developers import required packages, load the appropriate driver, create a connection, execute queries, process result sets, and close connections. The code sample demonstrates these steps by connecting to a MySQL database table and printing the results.

Uploaded by

pandivenkatesh n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

JDBC

JDBC is an API that allows Java applications to connect to databases. It supports both two-tier and three-tier architectures. To connect using JDBC, developers import required packages, load the appropriate driver, create a connection, execute queries, process result sets, and close connections. The code sample demonstrates these steps by connecting to a MySQL database table and printing the results.

Uploaded by

pandivenkatesh n
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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