Sie sind auf Seite 1von 5

JDBC (Java Database Connectivity)

Network: Interconnection between 2 or more computers is called Network.


The Advantage of Network is to send or receive information from one
computer to another. A computer that receives Information or some Service
is called Client. And Computer which Provides required Service is called
Server.

Database:
Database is Repository of Data. Using Database we can Store Data
Permanently and retrieve Data When ever Needed by using some Queries.
Examples are Oracle, Microsoft SQL Server, MySQL etc...
DBMS:
There are 3 types
1)RDBMS(Relational Database Management Systems )
It's able to Store data in form of tables, it will use SQL to Perform
data manipulations.
2) OODBMS(Object Oriented Database Management Systems)
Its able to store data in the form of Objects, by following Object
Oriented features and it will use 'Object Query Language'.
3) ORDBMS(Object Relational Database Management Systems)
Its able to store data in form of both Objects and Tables, it will use
SQL3 as Query language to perform Operations on data.
SQL3 = (SQL2 + OQL)
TSA-(Buffers, JAVA Objects)

File Systems
PSA

DBMS
DataWarhouse

RDBMS
ODBMS
ORDBMS
(SQL3 =SQL2+OQL)

Query Processing System:


When we Submit an SQL Query to Database, then DBE will take that Query
and Perform execution by following steps:
i) Query Tokenization
It will take provided Sql Query and generate Stream of Tokens as
Output.
ii) Query Parsing:
It will take stream of tokens as Input, Constructing a Tree called as QueryTree and checking whether any syntax errors available or not in provided Sql
Query.
--if Query Tree is Constructed Successfully then no errors available in SQL
Query.
---if Query Tree is not constructed Successfully then some Errors existed in
Provided SQL query.
iii) Query Optimization:
This phase will take Query tree as Input, it will apply number of
Optimization techniques on Query Tree in order to reduce Memory utilization
and Execution Time. Finally it will generate Optimized Query Tree as Output.
iv) Query Execution:
This Phase will take Optimized Query Tree as Input and will execute
Optimized Query Tree by having Interpreters.

DB

sql> Select * from Employee;

Eno Ename Esal


101 AAA
5000
102 BBB
8000

En
o
10
1
10
2

DBE

Ena
me
AAA
BBB

Query
Tokenize

Stream of Tokens

Query
Parsing

Query Tree

SAL
500
0
800
0

Query
Optimization Optimised Query Tree
Query Execution

JDBC
-JDBC is a Step by Step Procedure to interact with Database from JAVA
Applications in order to perform Database operations from java Applications.
-Java Database Connectivity is an API, that helps Programmer to write Java
Programs to connect with DB, retrieve data from DB and perform various
operations on Data.
-To Execute JDBC applications we need a Convertor to convert Database
Logic from JAVA Representation to Query Language Representation and viceversa. We Use Convertor 'Driver'.
- Driver : Driver is an Interface existed between Java Application and
Database, it is used to Map JAVA API calls to Query Language API calls
And Query Language API calls to JAVA API calls.

JAVA
Appl
----------------------------------------

Driver

Databas
e

B
E

- Sun Microsystems has provided "Driver" as an Interface inform of


"Java.sql.Driver" and thus Sun Microsystems has given option to all database
Vendors to have their own Implementation Classes for the interface
"Java.Sql.Driver".
-Thus Database Vendors have provided their own Implementation classes for
Driver Interface. There are around 180+ databases for which 180+ driver
exists but, all drivers are classified in following types :
i) Type I Driver

- Type I Driver is also called as 'JDBC.ODBC' driver or 'Bridge Driver'.


- Type I Driver is Reference Implementation for Driver Interface provided
by Sun Microsystems {sun.jdbc.odbc.jdbcodbcDriver}.
-It's provided on base of Microsoft Product ODBC Driver[Open Database
Connectivity].
Oracle:
To connect to Oracle DB:--- olog(); //function
To execute a Command ----oexec(); // function
To disconnect from Oracle ----ologoff(); //function
Mysql :
To connect to MySql : mysql_connect(); //function
To Execute a command: mysql_execute(); //function
To disconnect from Mysql : mysql_disconnect(); //function
ODBC(Open Database Connectivity)
It's an API Document, using these functions a programmer can communicate
with any Database. it is created by Microsoft Corpration.
JDBC API
Sun Microsystems, have created a API Document named JDBC API.
Here, JDBC API is defined in " Java.SQL.* " Package
JAVA.SQL. * package Contains Interfaces :-- Connection
Statement
ResultSet
ResultSetMetaData
PreparedStatement
CallableStatement
Driver
Classes: Date, Time, DriverManager, etc...

Oracle Queries:
Create table EmpTab(eno int, ename Varchar2(30), Salary float);
Insert into EmpTab values(&eno, '&ename', &salary);
Insert into EmpTab values(E-111, 'Galvin', 12000);
Update EmpTab set Salary = Salary+1000 where eno = E-111;
Delete from EmpTab where eno=1001;

Commit
To save all the Changes into the Database.
Rollback
To Un-Save all the Changes made to Database.
MySQL
To Show DataBases : show databases;
To Show Tables: show Tables;
to Show Description: desc emptab;
Stages in JDBC Program :
The following stages are used by JAVA Programmers' While using JDBC in
Programs
1) Registering the Driver:

Das könnte Ihnen auch gefallen