0% found this document useful (0 votes)
94 views6 pages

Register The Driver 2. Create A Connection 3. Create SQL Statement 4. Execute SQL Statement 5. Closing The Connection

JDBC is an API that provides standard Java-to-database connectivity and allows Java programs to access databases. It works as an interface between Java programs and databases by establishing a connection between them so data can be sent from Java code to a database for storage and future use. The key aspects of JDBC include registering a JDBC driver, creating a connection, executing SQL statements, extracting result sets, and closing the connection.
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)
94 views6 pages

Register The Driver 2. Create A Connection 3. Create SQL Statement 4. Execute SQL Statement 5. Closing The Connection

JDBC is an API that provides standard Java-to-database connectivity and allows Java programs to access databases. It works as an interface between Java programs and databases by establishing a connection between them so data can be sent from Java code to a database for storage and future use. The key aspects of JDBC include registering a JDBC driver, creating a connection, executing SQL statements, extracting result sets, and closing the connection.
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

What is JDBC ?

JDBC is an acronym for Java Database Connectivity. It’s an advancement for ODBC ( Open Database
Connectivity ). JDBC is an standard API specification developed in order to move data from frontend to
backend. This API consists of classes and interfaces written in Java. It basically acts as an interface (not the
one we use in Java) or channel between your Java program and databases i.e it establishes a link between
the two so that a programmer could send data from Java code and store it in the database for future use.

1. Register the Driver


2. Create a Connection
3. Create SQL Statement
4. Execute SQL Statement
5. Closing the connection

There are following six steps involved in building a JDBC application −


 Import the packages: Requires that you include the packages containing the JDBC classes
needed for database programming. Most often, using import [Link].* will suffice.
 Register the JDBC driver: Requires that you initialize a driver so you can open a
communication channel with the database.
The driver class for the oracle database is [Link].
JDBC Driver is required to process SQL requests and generate result.
 Open a connection: Requires using the [Link]() method to create a
Connection object, which represents a physical connection with the database.
The connection URL for the oracle10G database
is jdbc:oracle:thin:@localhost:1521:xe where jdbc is the API, oracle is the
database, thin is the driver, localhost is the server name on which oracle is running,
we may also use IP address, 1521 is the port number and XE is the Oracle service
name. You may get all these information from the [Link] file.
Username: The default username for the oracle database is system.

Password: It is the password given by the user at the time of installing the oracle
database.

 Execute a query: Requires using an object of type Statement for building and submitting an
SQL statement to the database.
 Extract data from result set: Requires that you use the
appropriate [Link]() method to retrieve the data from the result set.
 Clean up the environment: Requires explicitly closing all database resources versus relying
on the JVM's garbage collection.

[Link] creates a connection with specific database

[Link] create an instance of a driver with the DriverManager.

[Link] This class manages database drivers.

[Link] It is an interface that provide methods to access the result


row-by-row.

[Link] Encapsulate all JDBC related exception.

[Link] This interface is used to execute SQL statements.

JDBC Procedure:

procedure
1. type java code and save

2. open oracle 11g and create database

3. open control panel

select system and security

select administrative tools

select odbc data source(64 bit)

click add-select oracle -XE and click finish

give data source name-employee click ok

4. open C:

open oracle exe

open app

open oracle

open product

then 11.2.0

open server

open jdbc

open lib

copy all

5. goto C:

program files

jdk1.8

jre
lib

ext

paste all

6. class path setting:

right click on this pc

goto properties

click advanced system setting

click environmental variables

class path setting:

environment variables

set path

Algorithm:

Step 1: Start

Step 2:-Create a Database Namely email

Step 3:-Create a Table "Email" With id,username, password as Columns

step 4:-Insert Values In The email Table

Step 5:-Now Copy The paths of Oracle Drivers and JDK To Environment Variables

Step 6:- Create a java JDBC program To Connect With Oracle Server And Also To Acces It

Step 7:-Link The Java JDBC program and Execute It

Step 8:-Stop The Program

Program:

SQL:
create table email(id int,eusername varchar(20),phone no: int);

insert into email values(1,’asd@[Link]’,9443444021);

insert into email values(2,’bcg@[Link]’,9223444091);

Java Program:

import [Link].*;

public class DBconnect

public static void main(String args[])

//load the driver

try{

//step1 load the driver class

[Link]("[Link]");

1.
//step2 create the connection object
Connection
con=[Link]("jdbc:oracle:thin:@localhost:1521:XE","email","manager");

//step3 create the statement object

Statement st=[Link]();

//step4 execute query

ResultSet rs=[Link]("select * from email");

//Extract data from ResultSet

while([Link]())

//step5 access each row(three column’s values) and display corresponding values

[Link]([Link](1)+ " " +[Link](2)+ " " +[Link](3));

}
//step5 close the connection object
[Link]();
}

catch(Exception e)

[Link](e);

Output:

javac [Link]

java DBconnect

1 asd@[Link] 9443444021

2 bcg@[Link] 9223444091

You might also like