JDBC stands for Java Database Connectivity is standard java API(Application programming Interface a type of documents which contains all the features of a product or software. It represent class and interface for communication each other.It can be created for application,libraries,operating system etc) for connecting java program and wide range of databases like MYSQL, ORACLE etc.
JDBC can be used in different type of executable work in java like:
3.Java Server Pages
There are six simple steps to connect database in java:
- Import statement: In this step we import java.sql.*; Packages containing jdbc classes.
- Creating Driver class: forName() method of Class. Class is used to register the driver class Syntax => Class.forName(“com.mysql.jdbc.Driver”);
3.Create a connection: The getConnection method of Driver Manager class used to establish connection with databse.
Connection conn = DriverManager.getConnection(“url”,”username”,”password”);
4.Create Statement: This is reponsible for query execute from database
5. ExecuteQuery= It returns the object of ResultSet which is responsible for get all records from tables.
ResultSet rs=stmt.executeQuery(“select * from tables”);
6. Close the connection