JDBC - Connection The programming involved to establish a JDBC connection is fairly simple. Here are these simple four steps − Import JDBC Packages: Add.

Slides:



Advertisements
Similar presentations
Java Database Connectivity (JDBC). 2/24 JDBC (Java DataBase Connectivity) - provides access to relational database systems JDBC is a vendor independent.
Advertisements

Basic JDBC Celsina Bignoli What is JDBC Industry standard for database- connectivity between the Java language and a wide range of.
Distributed Application Development B. Ramamurthy.
1 JDBC Java Database Connectivity. 2 c.pdf
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
Databases: Connectivity Dr Andy Evans. Databases Flat file, relational, or object orientated stores of data records and their relationships. Oracle MySQL.
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 11. DATABASE CONNECTIVITY IN JAVA JDBC Programming JDBC (Java Database Connectivity) is the specification of a.
Proposed Website By Raymond Chieng and Tim. This website design is based on a local Chinese restaurant which basically need to facilitate online ordering.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
Dale Roberts 8/24/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
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
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
JDBC Java Database Connectivity. What is an RDBMS? Relational database management system. There are other kinds of DBMS. Access is a GUI on a JET RBDMS.
Helena Pomezná, ciz034 St. skupina: L392 FEI, VŠB-TUO Ak. rok. 2002/2003 Download:
CS178 Database Management “JDBC”. What is JDBC ? JDBC stands for “Java DataBase Connectivity” The standard interface for communication between a Java.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Active Server Pages ASP is Microsoft’s server-side script engine for dynamically-generated web pages. Most common language used is VBScript. If you use.
MySQL, Java, and JDBC CSE 3330 Southern Methodist University.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JAVA Database Access. JDBC The Java Database Connectivity (JDBC) API is the industry standard for database- independent connectivity between the Java.
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
Object-Oriented Software How does it differ from procedural? How is it similar to procedural? Why has it become so popular? Does it replace or supplement.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
JDBC Java and Databases, including Postgress. JDBC l Developed by Industry leaders l Three main goals: –JDBC should be an SQL-level API –JDBC should capitalize.
 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.
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 Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture12: Accessing Databases.
Index and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
JDBC – Java DataBase Connectivity. JDBC API Overview JDBC is Java API that allows the Java programmers to access database management system from Java.
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.
Java Database Connectivity (JDBC). Topics 1. The Vendor Variation Problem 2. SQL and Versions of JDBC 3. Creating an ODBC Data Source 4. Simple Database.
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
Computer Science [3] Java Programming II - Laboratory Course Lab 9: Accessing Databases with JDBC Instructions on Setting Accesses Connecting to and Querying.
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.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
225 City Avenue, Suite 106 Bala Cynwyd, PA , phone , fax Connecting to a Database.
16 Java Database Connectivity. 2 Understand the JDBC Understand the steps of the JDBC: 1.) Importing packages 2.) Opening a connection to a database 3.)
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.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
JAVA DATABASE OOP Praktek dengan Java Miswar,S.st Sumber : Eddy Muntina Dharma,ST,MT.
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.
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.
CS422 Principles of Database Systems JDBC and Embedded SQL Chengyu Sun California State University, Los Angeles.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
JSP and DB.
JDBC and OCCI 10/29/2017.
Java Access to RDB Relational databases (RDBs) dominate today, due to:
Interacting with Database
Lec - 14.
Java swings.
ODBC, OCCI and JDBC overview
JDBC Database Management Database connectivity
Advanced Web Automation Using Selenium
HW#4 Making Simple BBS Using JDBC
Interacting with Database
Super Market Management
Java Database Connectivity
Using a Database with JDBC
JAVA DATABaSE CONNECTIVITY
Java API for Database Connectivity
JDBC Example.
Presentation transcript:

JDBC - Connection The programming involved to establish a JDBC connection is fairly simple. Here are these simple four steps − Import JDBC Packages: Add import statements to your Java program to import required classes in your Java code. Register JDBC Driver: This step causes the JVM to load the desired driver implementation into memory so it can fulfill JDBC requests. Database URL Formulation: This is to create a properly formatted address that points to the database to which we wish to connect. Create Connection Object: Finally, code a call to the DriverManager object's getConnection( ) method to establish actual database connection.

Step 1 : Import JDBC Packages Tell the Java compiler where to find the classes you reference in your code. Placed at the very beginning of your source code. Example: import java.sql.* ; // for standard JDBC programs import java.math.* ; // for BigDecimal and BigInteger support

Step 2 : Register JDBC Driver Registering the driver is the process by which the Oracle driver's class file is loaded into the memory, so it can be utilized as an implementation of the JDBC interfaces. Approach I - Class.forName() Dynamically load the driver's class file into memory, which automatically registers it Approach II - DriverManager.registerDriver() While using a non-JDK compliant JVM, such as the one provided by Microsoft.

Approach 1 - Example try { Class.forName("oracle.jdbc.driver.OracleDriver"); } catch(ClassNotFoundException ex) { System.out.println("Error: unable to load driver class!”); System.exit(1); }

try { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); } catch(ClassNotFoundException ex) { System.out.println("Error: unable to load driver class!"); System.exit(1); catch(IllegalAccessException ex) { System.out.println("Error: access problem while loading!"); System.exit(2); catch(InstantiationException ex) { System.out.println("Error: unable to instantiate driver!"); System.exit(3); }

Approach 2 - Example try { Driver myDriver = new oracle.jdbc.driver.OracleDriver(); DriverManager.registerDriver( myDriver ); } catch(ClassNotFoundException ex) { System.out.println("Error: unable to load driver class!"); System.exit(1); }

Step 3: Database URL Formulation DriverManager.getConnection() method getConnection(String url) getConnection(String url, Properties prop) getConnection(String url, String user, String password) A database URL is an address that points to your database.

Popular JDBC driver names and database URL. RDBMSJDBC driver nameURL format MySQLcom.mysql.jdbc.Driver jdbc:mysql://hostname/ databaseName ORACLE oracle.jdbc.driver.OracleDriv er ort Number:databaseName DB2 COM.ibm.db2.jdbc.net.DB2D river jdbc:db2:hostname:port Number/databaseName Sybasecom.sybase.jdbc.SybDriver jdbc:sybase:Tds:hostname: port Number/databaseName

Step 4: Create Connection Object Type 1: Using a Database URL with a username and password String URL = String USER = "username"; String PASS = "password" Connection conn = DriverManager.getConnection(URL, USER, PASS); Type 2: Using Only a Database URL String URL = Connection conn = DriverManager.getConnection(URL)

Type 3: Using a Database URL and a Properties Object A Properties object holds a set of keyword-value pairs. It is used to pass driver properties to the driver during a call to the getConnection() method import java.util.*; String URL = Properties info = new Properties( ); info.put( "user", "username" ); info.put( "password", "password" ); Connection conn = DriverManager.getConnection(URL, info);

Closing JDBC Connections - conn.close(); It is required explicitly to close all the connections to the database to end each database session. Relying on the garbage collection, especially in database programming, is a very poor programming practice. A finally block always executes, regardless of an exception occurs or not. So the conn close is put up in the finally block.