JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.

Slides:



Advertisements
Similar presentations
Murach’s Java SE 6, C21© 2007, Mike Murach & Associates, Inc.Slide 1.
Advertisements

Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
JDBC - Java Database Connectivity The objectives of this chapter are: To describe the architecture of JDBC To outline the classes in the java.sql package.
Java, Access, SQL, HTML. Three-tier architecture involves: Client - Browser Server - Tomcat Database - Access - Server-side language - JSP could just.
1 JDBC Java Database Connectivity. 2 c.pdf
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
EmbeddedSQL: 1 Impedance Mismatch Problem Problem : How to connect SQL statements with conventional programming languages Different models of language.
CSE470 Software Engineering Fall Database Access through Java.
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
Java MS Access database connectivity Follow these steps: 1)Go to the start->Control Panel->Administrative Tools- > data sources. 2)Click Add button and.
JDBC CS 122. JDBC zJava Database Connectivity zDatabase Access Interface Õprovides access to a relational database (by allowing SQL statements to be sent.
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 11. DATABASE CONNECTIVITY IN JAVA JDBC Programming JDBC (Java Database Connectivity) is the specification of a.
Introduction to JDBC (Java Database Connectivity).
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
1 CSC 440 Database Management Systems JDBC This presentation uses slides and lecture notes available from
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 8 Object Oriented Programming in Java Advanced Topics Java Database.
Java Database Connectivity Vijayan Sugumaran Department of DIS Oakland University.
© Wang Bin 2004 JDBC ----Java Database Connectivity.
CSE470 Software Engineering Fall Database Access through Java.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Java Utility Classes CS 21b. Some Java Utility Classes Vector Hashtable StringTokenizer * import java.util.*;
1 Java DataBase Connectivity JDBC java.sql.*. 2 Java DataBase Connectivity Draft release of JDBC spec (3/96) Java API for executing SQL statements (Since.
JDBC. JDBC Drivers JDBC is an alternative to ODBC and ADO that provides database access to programs written in Java.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
 What software components are required?  How do I install the Oracle JDBC driver?  How do I connect to the database?  What form is the data in and.
Introduction to JDBC Michelle Lee, Ye Wu & Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
JDBC  The JDBC (Java Database Connectivity) API helps a Java program to access a database in a standard way  JDBC is a specification that tells the.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
Accessing Database using JDBC. JDBC Objectives Gain basic knowledge of Java JDBC Become familiar with the basics of interacting with a database using.
COMP201 Java Programming Topic 15: Database Connectivity JDBC Reading: Chapter 4, Volume 2.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
Copyright  Oracle Corporation, All rights reserved. 6 Accessing a Database Using the JDBC API.
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
JDBC CS 124. JDBC Java Database Connectivity Database Access Interface provides access to a relational database (by allowing SQL statements to be sent.
Presentation On How To Create Connection To A Database.
Li Tak Sing COMPS311F. Database programming JDBC (Java Database Connectivity) Java version of ODBC (Open Database Connectivity) ODBC provides a standard.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
CSI 3125, Preliminaries, page 1 JDBC. CSI 3125, Preliminaries, page 2 JDBC JDBC stands for Java Database Connectivity, which is a standard Java API (application.
Basics of JDBC.
JDBC (Java Database Connectivity)
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
1 JDBC – Java Database Connectivity CS , Spring 2010.
JDBC I IS Why do we have databases?
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
6-1 JAVA DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
JSP/Database Connectivity Instructor: Dr. M. Anwar Hossain.
Java Database Connectivity JDBC. Open Database Connectivity developed by Microsoft to provide interaction with databases using SQL. Use the JDBC-ODBC.
JDBC Statements The JDBC Statement, CallableStatement, and PreparedStatement interfaces define the methods and properties that enables to send SQL or PL/SQL.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java program to connect to any database.
JSP and DB.
CompSci 280 S Introduction to Software Development
Database: JDBC Overview
Interacting with Database
Lec - 14.
JDBC Database Management Database connectivity
Database JDBC Overview CS Programming Languages for Web Applications
HW#4 Making Simple BBS Using JDBC
Introduction to Server-Side Web Development using JSP and Databases
Objectives In this lesson, you will learn about:
Interacting with Database
JDBC – ODBC DRIVERS.
Bolat Azamat, Kim Dongmin
JDBC Example.
Presentation transcript:

JDBC

What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database

How to use JDBC Step1: First make a database Step2: Create tables Step3: Create data source

JDBC library in Java To use JDBC in java, you need to know about –Connection –Statement –ResultSet –DriverManager All these classes are provided in pacakkage java.sql.*.

Steps to use JDBC in Java Initialize variables Register or Load Driver Open a Connection Execute Sql Statement Close the Connection

Initialize Variables You need following variables Connection con; Statement stmt; Initialize variable to value null Connection con = null; Statement stmt = null;

Load Driver To load driver you need to use Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); sun.jdbc.odbc.JdbcOdbcDriver is the name of driver. Class.forName() function loads the driver in memory.

Create Connection After loading driver, you need to create a connection Create connection means, you need to connect your java program with the database. To connect to a database you must configure the DSN first DSN is an acronym for Data Source Name

What is DSN DSN is an acronym for Data Source Name DSN act as an interface between your java application and Database To create DSN –Open Control Panel –Administrative Tools –ODBC

Create Connection Contd After loading driver and creating DSN, next step is to create a connection. To create a connection conn = DriverManager.getConnection("jdbc:odbc:cdb"); DriverManager class getConnection functions takes DSN as input argument And returns an object of type Connection

Create Statement After creating connection, you need to create statement Statement stmt = conn.createStatement(); conn is a connection object created in previous slide

Execute Query After connection is created successfully, you need to execute query There are 2 types of query –That gets record from database –That insert or update or delete record

Insert or update or delete record To insert record in database, use method executeUpdate of statement class. int i = stmt.executeUpdate("INSERT INTO personal VALUES('"+lname+"','"+fname+"','"+sex+"','"+salary+"','"+exp+"')"); This method takes as input “Insert” query statement. This method returns 1 (success) or 0 (failure). You can replace “Insert” query statemetn with update or delete query statement.

Get record from database To retrieve or get record from database executeQuery() method is used. ResultSet rs = stmt.executeQuery(“Select lname, fname from personal"); The method executeQuery() takes “select” statement as input. The method executeQuery() returns an object of type ResultSet.

Complete Program for Inserting a record in Database <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc:cdb"); Statementstmt = conn.createStatement(); %>

Contd…. String lname = request.getParameter("fname"); String fname = request.getParameter("lname"); String sex = request.getParameter("sex"); String salary = request.getParameter("salary"); String exp = request.getParameter("experience");

Contd…. i = stmt.executeUpdate("INSERT INTO personal VALUES('"+lname+"','"+fname+"','"+sex+"','"+salary+"','"+e xp+"')"); if (i ==1) { System.out.println("success"); //response.sendRedirect("conjoint.html"); } else {System.out.println("There has been some problem in saving your personal information. Kindly fill the personal information again"); }

Complete Program for Retrieving records from query Connection conn = null; Statement stmt = null; ResultSet rs = null;

Contd…. Class.forName("sun.jdbc.odbc.JdbcOdbcD river"); conn = DriverManager.getConnection("jdbc:odbc: cdb"); stmt = conn.createStatement();

Contd…. rs = stmt.executeQuery("Select fname, lname from personal"); while(rs.next()) { System.out.println(rs.getString(1) + " " +rs.getString(2)); // rs.next(); } %>