Académique Documents
Professionnel Documents
Culture Documents
JDBC CONNECTIVITY
CONNECTING JAVA PROGRAM WITH ORACLE DB
Java JDBC
• JDBC Driver is a software component that enables java application to interact with
the database.
Java Database Connectivity with Oracle
To connect java application with the oracle database, we need following information:
The thin driver converts JDBC calls directly into the vendor-specific database protocol.
That is why it is known as thin driver. It is fully written in Java language.
Java Database Connectivity with 5 Steps
• There are 5 steps to connect any java application with the database using JDBC.
These steps are as follows:
• Register the Driver class
• Create connection
• Create statement
• Execute queries
• Close connection
Java Database Connectivity with 5 Steps
• Create connection
The getConnection() method of DriverManager class is used to establish
connection with the database.
• Create statement
The createStatement() method of Connection interface is used to create
statement. The object of statement is responsible to execute queries with the
database.
• Execute queries
The executeQuery() method of Statement interface is used to execute queries to
the database. This method returns the object of ResultSet that can be used to get
all the records of a table.
• Close connection
By closing connection object statement and ResultSet will be closed automatically.
The close() method of Connection interface is used to close the connection.
try {
ex.printStackTrace();
ex.printStackTrace();
}
}
}
COMPILE YOUR CODE
Javac yourfilename.java
Before you execute your code
1. Create table students with columns std_id (primary key), std name (not null)
2. Insert 5 different records in student table and show on console whether all records
are successfully inserted or not.
3. Select inserted records
4. Update 2 selected records and display their success on console.
5. Select updated records
6. Delete one of the updated record and display its success on console.
7. Select all the records and print them on console.