JDBC. Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most.

Slides:



Advertisements
Similar presentations
Connecting to Databases. connecting to DB DB server typically a standalone application Server runs on localhost for smaller sites –i.e. Same machine as.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Java and Databases CS-328 Dick Steflik. Database Drivers Think of a database as just another device connected to your computer like other devices it has.
Distributed Application Development B. Ramamurthy.
SQL (Structured Query Language) X/OPEN Call Level Interface For SQL ODBC (Open DataBase Connectivity) API JDBC (Java DataBase Connectivity) API SQL (Structured.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
DT228/3 Web Development Databases. Database Almost all web application on the net access a database e.g. shopping sites, message boards, search engines.
1 Design patterns Lecture 4. 2 Three Important skills Understanding OO methodology Mastering Java language constructs Recognizing common problems and.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
JDBC / ODBC JDBC is the java API that facilitate interaction of a java application with the DBMS. FIRST APPROACH:
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.
Introduction to DBMS and SQL Introduction to DBMS and SQL GUIDED BY : MR. YOGESH SAROJ (PGT-CS) MR. YOGESH SAROJ (PGT-CS) Presented By : JAYA XII –COM.
Database Lecture # 1 By Ubaid Ullah.
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
Dr R R DOCSIT, Dr BAMU. Basic Java : Introduction to JDBC 2 Objectives of This Session State what is Java Database Connectivity State different.
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,
Connecting to Oracle using Java November 4, 2009 David Goldschmidt, Ph.D. David Goldschmidt, Ph.D.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
JDBC. Preliminaries Database Database Collection of data Collection of data DBMS DBMS Database management system Database management system Stores and.
Chapter 8 Databases.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
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.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Structured Query Language 1. Data Definition Language (DDL) is used to manage table and define data structure i.e. CREATE, ALTER, DROP Data Control.
JDBC Database Programming in Java Prepared by., Mrs.S.Amudha AP/SWE.
JDBC CHAPTER-2. JDBC - Java Database Connectivity. JDBC from Sun Microsystems provides API or Protocol to interact with different databases. With the.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
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.
DataBases and SQL INFSY 547 Spring Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:
Database Access Using JDBC BCIS 3680 Enterprise Programming.
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.
Transactions, Roles & Privileges Oracle and ANSI Standard SQL Lecture 11.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Basics of JDBC Session 14.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
JDBC Chapter 1 JDBC Introduction
JDBC - Java Database Connectivity. JDBC provides Java applications with access to most database systems via SQL The architecture and API closely resemble.
Advanced Java Session 5 New York University School of Continuing and Professional Studies.
Ch. NoNameMarks 01AWT24 02Networking18 03JDBC20 04Swing18 05Servlet20 Advance Java Programming.
JDBC. SQL(Structured Query Language) is divided into 1.DDL(Data Definition Language) create db, create table, alter table, drop db or table 2.DML(Data.
Databases and SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
SQL Basics Review Reviewing what we’ve learned so far…….
SQL. Structured Query Language ( SQL is a language of database, it includes database creation, deletion, fetching rows and modifying rows etc. ) SQL is.
DEPTT. OF COMP. SC & APPLICATIONS
Interacting with Database
ODBC, OCCI and JDBC overview
JDBC Database Management Database connectivity
PGT(CS) ,KV JHAGRAKHAND
Web Technologies IT230 Dr Mohamed Habib.
Client Access, Queries, Stored Procedures, JDBC
“Introduction To Database and SQL”
DATABASE MANAGEMENT SYSTEM
Interacting with Database
مقدمة في قواعد البيانات
Java Database Connectivity
SQL .. An overview lecture3.
ODBC and JDBC.
Java API for Database Connectivity
Lecuter-1.
Presentation transcript:

JDBC

Database is used to store data permanently. These days almost all Applications needs database to store its data persistently. Below are the most popular databases 1. MySQL 2. Oracle 3.SQL Server,etc… SQL(Structured Query Language) is used to interact with databases. SQL is case insensitive language.

SQL(Structured Query Language) is divided into 1.DDL(Data Definition Language): Queries related to creating or changing structure of db or table. Example: create db, create table, alter table(add column or drop column), drop db or table 2.DML(Data manipulation Language) insert, update, delete, truncate 3.DQL(Data Query Language) select 4.TCL(Transaction Control Language) commit, rollback a Transaction 5.DCL(Data Control Language) grant, revoke Privileges to/from a user. Generally DCL is used by DBA.

Commands show databases; - to view all existing databases in the database server use kkkk; - to select a specific database drop database aaaa; - completely destroy the database aaaa create database abcdef; - create the database abcdef show tables; - to view all tables in current database CREATE TABLE institute(id INT, name VARCHAR(50), addr VARCHAR(100)); - creates a table with the name institute, with three columns id, name, and addr DESC institute; - describe the structure of institute table INSERT INTO institute VALUES(2,'abc institute','jp ngr'); SELECT * FROM institute; INSERT INTO institute(id, name) VALUES(3,'some inst name'); SELECT name,addr FROM institute WHERE id=2; ALTER TABLE institute ADD COLUMN city VARCHAR(20); delete from institute where name like 'java%'; delete from institute; truncate institute; drop table institute;

Column Constraints Below are column constraints which can be specified while creating or altering table 1.NOT NULL – NULL Values not allowed 2.DEFAULT – default value is used, if no value is specified in insert stmt 3.PRIMARY KEY – ensures all values are different in a column, and NULL not allowed 4.AUTO_INCREMENT – Automatically increments a column value, when new record is inserted

Java Application (Console based app or Servlet or JSP) JDBC Driver Database Server Java Database Connectivity

JDBC(Java DataBase Connectivity) JDBC Acts as an interface between Java Application and Database Server. Package used for Java Applications to interact with database is java.sql JDBC is provided by database vendor JDBC is provided as jar(Java Archive) file, which need to added to the project.

MySQL Oracle SQL Server Sybase DB2,etc…

Java.sql package

You are also using the ojdb14.jar from Oracle, probably with a "thin" jdbc configuration, which means you are using a type-4 driver configuration. With such a configuration, you will only need to deploy the JDBC jar file with your database accessing program. The other options include a JDBC bridge, which really means an ODBC connection wrapped in JDBC clothing. This means you would have to configure your system for correct ODBC function, and then use a JAR file to access ODBC. Due to the extra "hop" of data through ODBC, one would expect it to be a bit slower than a type-4 access; however, there is a possibility that the ODBC is optimized to such a great extent for a particular situation, that the extra hop is negligible. As with most performance concerns, the truth is discovered by testing (in your environment). The type-2 drivers again use a Java (JDBC) API; however, they bridge the calls into a C or C++ style shared library, which then handles the real connection. If the driver is optimized to be so fast that the JNI setup / tear down calls are negligible in cost, then perhaps it might outperform type-4 drivers. Type 3 drivers basically proxy (or relay) the request to another network resource. That typically incurs an extra network hit, but again, that doesn't say much about actual performance. Type 4 drivers are the ones you probably want to stick with. The Java program connects directly to the database, meaning that if there is a problem, it will be captured entirely within the JVM of the program making the connection (type 1, it's in the ODBC layer, type 2 it's in the native compiled code, type 3 it's in the remote network proxy).

Type 1: JDBC-ODBC Bridge driver (Bridge) Type 2: Native-API/partly Java driver (Native) Type 3: AllJava/Net-protocol driver (Middleware) Type 4: All Java/Native-protocol driver (Pure) Currently Type4 driver is used Differs in Performances and portability

Type 1 Type 2 Type 3 Type 4

Difference between different types of JDBC driver comes from the fact how they work, which is basically driven by two factor, portability and performance. Type 1 JDBC driver is the poorest in terms of portability and performance, while type 4 JDBC driver is highly portable and gives best performance.

There are three different types of sql Statements in Java. 1.Statement 2.PreparedStatement 3.CallableStatement Statement uses actual sql query. In PreparedStatement, first the query is built without data. Then data is set, and executed. Advantage of prepared statement is same statement can execute multiple times, with different data. Execution of PreparedStatment is faster. CallableStatement is used to execute stored procedures in the database.