JDBC
JDBC
JDBC stands for Java Database Connectivity. JDBC is a Java API to connect and execute the
query with the database. It is a part of JavaSE (Java Standard Edition). JDBC API uses JDBC
drivers to connect with the database. There are four types of JDBC drivers:
We can use JDBC API to access tabular data stored in any relational database. By the help of
JDBC API, we can save, update, delete and fetch data from the database.
The java.sql package contains classes and interfaces for JDBC API. API (Application
programming interface) is a document that contains a description of all the features of a
product or software. It represents classes and interfaces that software programs can follow to
communicate with each other.
We can use JDBC API to handle database using Java program and can perform the following
activities:
o Create connection
o Create statement
o Execute queries
o Close connection
Class.forName("com.mysql.jdbc.Driver");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","password");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbcdata","root","");
3) Create the Statement object
The createStatement() method of Connection interface is used to create statement. The object of
statement is responsible to execute queries with the database.
1. Statement stmt=con.createStatement();
con.close();
*******************************************************************************
FirstJDBC.java