Download Slide 1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

IMDb wikipedia , lookup

Serializability wikipedia , lookup

Microsoft Access wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Oracle Database wikipedia , lookup

Functional Database Model wikipedia , lookup

Ingres (database) wikipedia , lookup

Concurrency control wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Database wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

SQL wikipedia , lookup

Versant Object Database wikipedia , lookup

ContactPoint wikipedia , lookup

PL/SQL wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Open Database Connectivity wikipedia , lookup

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 Database Connectivity
Java Application
(Console based app or Servlet or
JSP)
JDBC Driver
Database Server
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.