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 (Java Database Connectivity)

JDBC can be used in different type of executable work in java like:

1.Java Application

2.java Servlet

3.Java Server Pages

4.Enterprises javaBean

5.Java Applet

There are six simple steps to connect  database in java:

  1. Import statement: In this step we import java.sql.*; Packages containing jdbc classes.
  2. 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”);

Connection conn=DriverManager.getConnection(“jdbc:mysql://localhost/test”,”root”,”12345″);

4.Create Statement: This is reponsible for query  execute from database

   Statement stmt=conn.createStatement(); 

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



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s