JDBC Introduction

JDBC Introduction

In this tutorial, we are going to discuss about JDBC Introduction. With Core Java knowledge we can develop Stand Alone Applications. The Applications which are running on a Single Machine are called Stand Alone Applications.

E.g

Calculator, MS Word, Notepad, any Core Java Application

JDBC Introduction

If we want to develop Web Applications then we should go for Advanced Java. The Applications which are providing Services over the Web are called Web Applications.

E.g

waytoeasylearn.com, gmail.com, facebook.com, twitter.com

In Java we can develop Web Applications by using the following Technologies.

  • JDBC
  • Servlets
  • JSP’s

Where ever Presentation Logic is required i.e. to display something to the End User then we should go for JSP i.e. JSP meant for View Component.

Example

  • Display login page
  • Display inbox page
  • Display error page
  • Display result page etc.

Where ever some Processing Logic is required then we should go for Servlet i.e. Servlet meant for Processing Logic/ Business Logic. Servlet will always work internally.

Example

  • Verify User
  • Communicate with Database
  • Process End User’s Data etc.

From Java Application (Normal Java Class OR Servlet) if we want to communicate with Database then we should go for JDBC.

Example

  • To get Astrology Information from Database
  • To get Mails Information from Database etc.

In Java there are 3 Editions are available

  1. Java Standard Edition (JSE | J2SE)
  2. Java Enterprise Edition (JEE | J2EE)
  3. Java Micro Edition (JME | J2ME)

JDBC is the Part of JSE and Servlets and JSP’s are the Part of JEE.

1. Driver

To convert Java specific calls into Database specific calls and Database specific calls into Java calls.

2. Connection

By using Connection, Java Application can communicate with Database.

3. Statement

By using Statement Object we can send our SQL Query to the Database and we can get Results from Database.

4. ResultSet

ResultSet holds Results of SQL Query.

Steps for JDBC Application
  1. Load and Register Driver
  2. Establish Connection between Java Application and Database
  3. Create Statement Object
  4. Send and Execute SQL Query
  5. Process Results from ResultSet
  6. Close Connection

E.g

import java.sql.*; 

/**
 * 
 * @author ashok.mariyala
 *
 */
public class JdbcDemo { 
   public static void main(String[] args) throws Exception { 
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
      Connection con=DriverManager.getConnection("jdbc:odbc:demodsn","scott","tiger"); 
      Statement st = con.createStatement(); 
      ResultSet rs= st.executeQuery("select * from employees"); 
      while(rs.next()) { 
         System.out.println(rs.getInt(1)+".."+rs.getString(2)+".."+rs.getDouble(3)+"..."+rs.getString(4)); 
      }
      con.close(); 
   }
}

That’s all about the JDBC introduction. If you have any queries or feedback, please write us email at contact@waytoeasylearn.com. Enjoy learning, Enjoy Java.!!

JDBC Introduction
Scroll to top