What Is Java Database Connectivity (JDBC)? | How to Perform – DSRajeev Kumar
How to Perform JDBC?
JDBC stands for ‘Java Database Connectivity’.
It is an API that use to connect and execute the queries with the respective database.
The Code written in Java to connect with Database is known as Java Database Connectivity (JDBC).
Through this code we can:
- Connect to the database.
- Create a table in the database.
- Insert Record in database.
- Select the record in the database.
- Update the record in the database.
- Delete the record in the database.
Requirements to Perform JDBC
- Eclipse IDE
- Oracle 11g
- .jar file
1st Step: Connect/Create a Table in the Database
Class: it is a predefined class.
forname(): It is a static method of Class. It uses to load the Oracle driver.
- Connection Interface
It uses to store the connection for the specific database.
- getConnection(“jdbc:oracle:thin:@localhost:1521:”, “system”, “Tiger“)
- DataBase URL– jdbc:oracle:thin:@localhost:1521:
- User– System
- Password– Tiger
- The statement is an Interface
- createStatement(): it is a method that uses to create a Statement for sending SQL statements to the database.
- executeUpdate(): it is a method that uses to execute the given SQL statement, which may be an INSERT, UPDATE, or DELETE
- close (): this method is used to Close/Release this Connection object’s database and JDBC resources immediately instead of waiting for them to be automatically released.
2nd Step: Insert the Record in the Database
- PreparedStatement is an interface.
- Preparestatement(): it is a method that is used to create a PreparedStatement object for sending parameterized SQL statements to the database.
3rd Step: Select the Record in the Database
- ResultSet is an interface
- Executequery(): it is a method that is used to execute the given SQL statement, which returns a single ResultSet
4th Step: Update the Record in the Database
5th Step: Delete the Record in the Database
There are some steps that need for SQL:
- Enter “SQL command line” in the windows search
- Open Run SQL Command Line.
- Enter Connect in opened command line window.
- Enter a User name.
- Enter Password-It is not visible on the screen.
- Hit enter key and then Connect should display.
In this blog, I have explained easily how we can connect to Oracle database with java, not only this but also explained how to create tables/insert/select/update/delete records in the database.
Java Related Post