JAVA JDBC JAVA JDBC Java Database Programming Lamiaa Said.

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

JDBC. Java Database Connectivity (JDBC) Use the java.sql package to query and update the database. JDBC is an API that allows java to communicate with.
15-Jun-15 JDBC. JDBC is a Sun trademark It is often taken to stand for Java Database Connectivity Java is very standardized, but there are many versions.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 32 Java Database.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
Java Database Connectivity (JDBC) java.sql package to query and update the database. JDBC is an API that allows java to communicate with a database server.
1 Lecture 29 More on JDBC Overview  Objectives of this lecture  JDBC and its Drivers  Connecting to Databases (Java’s Connection class)  Querying a.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
Three-Tier Architecture Oracle DB Server Apache Tomcat App Server Microsoft Internet Explorer HTML Tuples HTTP Requests JDBC Requests Java Server Pages.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 37 Java Database Programming.
JDBC Java API for Database Connectivity. Layout of this recitation Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API –Classes.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 37 Java Database Programming.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
Java Database Connectivity (JDBC) Francisco Pajaro Saul Acosta Nahum Quezada Manuel Rubio.
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.
Helena Pomezná, ciz034 St. skupina: L392 FEI, VŠB-TUO Ak. rok. 2002/2003 Download:
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.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Java Database Connectivity ASE. Java Database Connectivity (JDBC) l JDBC – provides an interface to Relational Data Sources l JDBC library provides the.
Java Utility Classes CS 21b. Some Java Utility Classes Vector Hashtable StringTokenizer * import java.util.*;
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
 2004 Keith Vander Linden. All Rights Reserved. Calvin CollegeDepartment of Computer Science(1/25) Database Programming with JDBC Keith Vander Linden.
JDBC Tutorial MIE456 - Information Systems Infrastructure II Vinod Muthusamy November 4, 2004.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 37 Java Database.
Connecting to Oracle using Java November 4, 2009 David Goldschmidt, Ph.D. David Goldschmidt, Ph.D.
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.
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.
1 Chapter 25 Java Database Programming. 2 Objectives F To understand the concept of database and database management systems (§25.2). F To understand.
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.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
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.
Java Database Connectivity. Java and the database Database is used to store data. It is also known as persistent storage as the data is stored and can.
MySQL and JDBC Tutorial ECT 7130 Hong Cheng. Supplement on MySQL ement/Supplement4bMySQL.pdf.
Copyright © 2002 ProsoftTraining. All rights reserved. Building Database Client Applications Using JDBC 2.0.
JDBC Database Programming in Java Prepared by., Mrs.S.Amudha AP/SWE.
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.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
Li Tak Sing COMPS311F. Database programming JDBC (Java Database Connectivity) Java version of ODBC (Open Database Connectivity) ODBC provides a standard.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
UNIT III - JDBC JDBC Overview – JDBC implementation – Connection class – Statements - Catching Database Results, handling database Queries. Networking–
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
Chapter 25 Java Database Programming
JDBC and SQLJ CIS 612 Spring JDBC JDBC is an API that enables database access from Java programs JDBC for DB access provides ◦ Portability across.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
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
Basics of JDBC.
Basics of JDBC Session 14.
JDBC (Java Database Connectivity)
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
Database: JDBC Overview
Interacting with Database
JDBC Database Management Database connectivity
Chapter 34 Java Database Programming
Database JDBC Overview CS Programming Languages for Web Applications
UNIT-2 Java Database Programming
Prof: Dr. Shu-Ching Chen TA: Sheng Guan
Java API for Database Connectivity
JDBC Example.
Presentation transcript:

JAVA JDBC JAVA JDBC Java Database Programming Lamiaa Said

What is a Database System? e.g., Access, MySQL, Oracle, and MS SQL Server

Database Application Systems The application program may use more than one DBMS

Examples of Simple SQL Statements Select statement select firstName, mi, lastName from Student where deptId = 'CS'; select firstName, mi, lastName from Student where deptId = 'CS' and zipCode = '31411'; select * from Student where deptId = 'CS' and zipCode = '31411';

Examples of Simple SQL Statements, cont. Insert statement insert into Course (courseId, subjectId, courseNumber, title) values ('11113', 'CSCI', '3720', 'Database Systems', 3);

Examples of Simple SQL Statements, cont. Update statement update Course set numOfCredits = 4 where title = 'Database Systems';

Examples of Simple SQL Statements, cont. Delete statement delete Course where title = 'Database System';

Java Database Connectivity (JDBC) Is a java API that allow java programs to access Database. The JDBC classes are contained in the Java package java.sql

The Architecture of JDBC

The JDBC-ODBC Bridge Is a database driver that utilize the ODBC driver to connect the database. This driver translates JDBC method calls into ODBC function calls. ODBC (Open DataBase Connectivity), is used to make it possible to access any data from any application, regardless of which (DBMS) is handling the data

JDBC Drivers A JDBC driver allows a Java application/client to communicate with a SQL database. A JDBC driver is a Java class. A JDBC driver converts program (and typically SQL) requests for a particular database.

Developing JDBC Programs

The JDBC Interfaces

JDBC Drivers A JDBC driver allows a Java application/client to communicate with a SQL database. A JDBC driver is a Java class. A JDBC driver converts program (and typically SQL) requests for a particular database.

Loading Drivers Statement to load a driver: –Class.forName("JDBCDriverClass"); –or DriverManager.registerDriver(new JDBCDriverClass()); A driver is a class. For example: DatabaseDriver ClassSource Access sun.jdbc.odbc.JdbcOdbcDriverAlready in JDK MySQL com.mysql.jdbc.DriverWebsite Oracle oracle.jdbc.driver.OracleDriverWebsite The JDBC-ODBC driver for Access is bundled in JDK. MySQL driver class is in mysqljdbc.jar Oracle driver class is in classes12.jar

Establishing Connections Connection connection = DriverManager.getConnection(databaseURL); DatabaseURL Pattern Accessjdbc:odbc:dataSource MySQLjdbc:mysql://hostname/dbname

Establishing Connections Examples For Access: –Connection connection = DriverManager.getConnection ("jdbc:odbc:ExampleMDBDataSource"); For MySQL: –Connection connection = DriverManager.getConnection ("jdbc:mysql://localhost/test"); For Oracle: –Connection connection = DriverManager.getConnection "scott", "tiger");

Creating and Executing Statements Creating statement: – Statement statement = connection.createStatement(); Executing statement (for update, delete, insert): – statement.executeUpdate("create table Temp (col1 char(5), col2 char(5))"); Executing statement (for select): –ResultSet resultSet = stmt.executeQuery ("select firstName, mi, lastName from Student where lastName " + " = 'Smith'");

Processing ResultSet Executing statement (for select): –ResultSet resultSet = stmt.executeQuery ("select firstName, mi, lastName from Student where lastName " + " ='Smith'"); Processing ResultSet (for select): //Iterate through the result and print the student names while (resultSet.next()) { System.out.println(resultSet.getString(1) + " " + resultSet.getString(2) + " " + resultSet.getString(3)); }

Simple JDBC Example import java.sql.*; public class SimpleJdbc { public static void main(String[] args) { try { DriverManager.registerDriver(new com.mysql.jdbc.Driver()); Connection connection = DriverManager.getConnection ("jdbc:mysql://localhost/test"); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery ("select firstName, mi, lastName from Student where lastName " + " = 'Smith'"); while (resultSet.next()) System.out.println(resultSet.getString(1) + "\t" + resultSet.getString(2) + "\t" + resultSet.getString(3)); connection.close(); } catch (Exception e) { System.err.println("Exception: "+e.getMessage()); }

Processing Statements Once a connection to a particular database is established, it can be used to send SQL statements from your program to the database. JDBC provides the Statement, PreparedStatement, and CallableStatement interfaces to facilitate sending statements to a database for execution and receiving execution results from the database.

executeQuery executeUpdate The executeQuery, and executeUpdate Methods The methods for executing SQL statements are execute, executeQuery, and executeUpdate, each of which accepts a string containing a SQL statement as an argument. This string is passed to the database for execution. The executeQuery method should be used if the execution produces a single result set, such as the SQL select statement. The executeUpdate method should be used if the statement results in a single update count or no update count, such as a SQL INSERT, DELETE, UPDATE, or DDL statement.

PreparedStatement The PreparedStatement interface is designed to execute dynamic SQL statements and SQL-stored procedures. These SQL statements and stored procedures are precompiled for efficient use when repeatedly executed. PreparedStatement pstmt = connection.prepareStatement ("insert into Student (firstName, mi, lastName) + values (?, ?, ?)"); Pstmt.setStirng(1, name); ……

Questions 24