JDBC: is an acronym for 'Java Data Base Connectivity'. It is used for accessing the databases from Java Applications. JDBC API allows to do CRUD operations on Database.
Steps to connectivity between Java program and Database:
Steps to connectivity between Java program and Database:
- Loading the Driver
- Create the Connections
- Create a Statement
- Execute the Query
- Close the Connections.
Loading the Driver:
We can register the driver using Class.forName("oracle.jdbc.driver.OracleDriver");
Class.forName() load the driver's class file into memory, which automatically registers it.
In JDBC API, we have java.sql.Driver, it is only an interface and it is available in JDK.
Create the Connections:
We can establish the connection using
Connection conn=DriverManager.getConnection(String url, String user, String password);
url can be created as "jdbc:oracle:thin:@hostname:port Number:databaseName"
Create a Statement: Interface define the methods and properties that enable you to send SQL or PL/SQL commands and receive data from your database.
Statement st = con.createStatement();
In JDBC API, we have java.sql.Driver, it is only an interface and it is available in JDK.
Create the Connections:
We can establish the connection using
Connection conn=DriverManager.getConnection(String url, String user, String password);
url can be created as "jdbc:oracle:thin:@hostname:port Number:databaseName"
Create a Statement: Interface define the methods and properties that enable you to send SQL or PL/SQL commands and receive data from your database.
Statement st = con.createStatement();
Execute the Query: Reads data from a database query and returns the data in a result set. The java.sql.ResultSet interface represents the result set of a database query.
ResultSet rs=stmt.executeQuery("select query);
Close the Connections:
The close() method of Connection interface is used to close the connection.
conn.close()
ResultSet rs=stmt.executeQuery("select query);
Close the Connections:
The close() method of Connection interface is used to close the connection.
conn.close()
0 comments:
Post a Comment