SlideShare a Scribd company logo
JAVA DATABASE CONNECTIVITY
Submitted By:-
V. Priyanka, II-M.Sc.,
M. Lavanya, II-M.Sc.,
S. Suryakala, II-M.Sc.,
(N. S. College of Arts & Science, Theni, TamilNadu.)
JAVA DATABASE CONNECTIVITY
JDBC DRIVERS:-
The JDBC driver class handles the connection to the
database.
The java SDK contain only one JDBC driver, a jdbc-odbc
bridge that can communicate with an existing open
database connectivity(ODBC) driver.
Other database need a JDBC driver specific to that
database.
The jdbc-odbc bridge accepts Uniform Resource
Location(URLs)starting with jdbc:odbc: and use the next field
in that URL to specify the data source name.
The data source name identifiers the particular database
scheme you wish to access.
There are four type of JDBC drivers:
 Type 1 Drivers
 Type 2 Drivers
 Type 3 Drivers
 Type 4 Drivers
Type 1 Driver:-
Type 1 JDBC drivers are the bridge drivers such as the jdbc-
odbc bridge.
These drivers rely on an intermediary such as ODBC to
transfer the SQL calls to the database.
bridge drivers often only one rely on native code.
The jdbc-odbc library native cod is part of the java 2 virtual
machine.
Type 2 Drivers:-
Type 2 Drivers use the existing database API to communicate
with the database on the client.
Although Type 2 drivers are faster than Type 1 drivers use
native code and require additional permissions to work in an
applet.
A Type 2 drivers might need client-side database code to
connect over the work.
Type 3 drivers:-
Type 3 Drivers calls the database API on the server.
JDBC requests from the client are first proxied to the JDBC
driver on the server to run.
This clients can use type 3 and 4 drivers, as they need to native
code.
Type 4 Drivers:-
The highest level of driver reimplements the database network
API in the java language.
Type 4 Drivers can also be used on thin clients, as they also
have no native code.
DATABASE CONNECTIONS:-
A database connection can be established with a call to the
drivermanager.getconnection method.
The call takes a URL that identifies the database and optionally,
the database login user name and password.
Connection con=DriverManager.getconnection (url);
Connection con=DriverManager.getconnection (url,
“user”, “password” );
After a connection is established, a statement can be run against
the database. The result of the statement can be retrieved and
the connection is closed.
STATEMENTS:-
There are three basic types of SQL statements used in the JDBC
API. They are
Callable Statement
Statement
Prepared Statement
CALLABLE STATEMENTS:-
A callable statement is the statement, which lets you execute SQL stored
procedure. Once you have established a connection to a database, you can use
the connection.prepareCall( ) method to create a callable statement.
EX:-
Creates a callable Statement object with three parameters for storing account
login information.
Callable Statement cs=
con . prepareCall (“{call accountlogin(?,?,?)}”);
cs . setString (1, theuser);
cs . setString (2, password);
cs.registerOutParameter(3,Types,DATE);
cs.executeQuerry( );
Date lastLogin=cs . getdate(3);
Statements:-
The statement interfere execute a simple SQL statement
with no parameters.
Query Statement:-
This code segment creates a statement object and calls the
Statement . executeQuerry( ) method to select text from the dba
database.
The result of the query are returned in a ResultSet Object. The
required result are then retrieved from a ResultSet Object.
Example:-
Statement stmt = con . createStatement();
ResultSet results = stmt.executeQuery(“SELECT
TEXT FROM dba”);
Update Statements:-
This code segment creates a Statement object and calls the
Statement . executeUpdate method to add an email address to a
table in the dba database.
String updateString = “INSERT INTO dba
VALUES(SOME TEXT)”;
int count = stmt.executeUpdate(updateString);
Prepared Statement:-
The PreparedStatement interface descends from the Statement
interface and uses a template to create a SQL request.
Use a PreparedStatement to send precompiled SQL, statements
with one or more parameters.
Query Prepared Statement:-
This code segment creates a PreparedStatement object to
select user data based on the user’s email address. The question
mark(“?”)indicates that the statement has one parameter.
Example:-
PreparedStatement pstmt = con. PreparedStatement(“select
The user from registration where email address like ?”);
// Initialize first parameter with email address//
Pstmt . setString(1,emailAddress);
ResultSet results = ps . executeQuerry();
Update Prepared Statement:-
This code segment creates a PreparedStatement object to
update a seller’s registration record. The template has five
parameters.
PreparedStatement pstmt = con. PreparedStatement(“Insert
into registration(theuser, password, email address,
creditcard, balance) values ?,?,?,?,?)”);
Ps.setString(1,theuser);
Ps.setString(2,password);
Ps.setString(3,email address);
Ps.setString(4,credit card);
Ps.setDouble(5,balance);
Ps.setUpdate();
Caching Data Base Connectivity:-
The Prepared Statement concept of reusing requests can
be extended for caching the results of a JDBC call.
Results Set:-
The ResultSet interface managers access to data returned from
a query.
The data returned, equals one row in a database table.
Some queries return only one row of data while many queries
return multiple rows of data.
Scrolling Result:-
JDBC 2.0 introduced scrollable results sets whose values can
be read and updated if reading and updating is supported by the
underlying database.
one advantage to the new result set is you can update a set of
matching rows without issuing an additional execute Update
call.
The updates are made using JDBC calls and so on custom SQL
commands need be generated.
Controlling Transactions:-
JDBC statements are processed in full auto-command mode.
This mode works well for a single database query, but if an
operation depends on several database statements that all have
to completely successfully or the entire operation is cancelled,
a finer transaction is needed.
To use transaction management in the JDBC platform, you first
need to disable the full auto-commit mode by calling:
Connection con = getConnection( );
con . setAutoCommit(false);
At this point ,you can either commit any following JDBC
statements or undo any updates by calling the connection.
rollback method.
The rollback call is commonly placed in the Exception
Handler, although it can be placed anywhere in the transaction
flow.
Escaping Character:-
The JDBC API provide the escape keywords you can specify the
character you want to escape characters.
EX:-
stmt.executeQuery(“select tax from sales where tax like
‘10%’ (escape ‘’)”);
To solve this problem, the following method escape any ‘symbol
found in the input line’ is used.
This method can be extended to escape any other character such
as commas, that the database or database driven might interpret
another way.
Program:
static public String escapeLine (String s)
{
String retvalue = s;
if (s. indexOf (“ ‘ ‘ “); !=-1)
{
StringBuffer hold = new StringBuffer ();
char c;
for(int i=0; I<s.length (); i++)
{
hold.append (“ ‘ ‘ “);
}
else
{
hold.append(c);
}
}
Retvalue=hold.toString( );
}
Return retvalue;}
Mapping Data Base Types:-
JDBC type such as Integer that are represented as an Integer in
most popular database.
The JDBC type for a table column does not match the type as it
represented in the database.
This means calls to ResultSet . getObject, preparedStatement .
setobject and callableStatement.getobject()
Mapping Date Types
The DATE type is where most mismatches occur. This is
because the java.util.Date class represents both Date and Time but
SQL has the following three types to represent data and time
information.
 A DATE type that represents the date only (03/23/99)
 A TIME type that specifies the time only (12:03:59)
 A TIMESTAMP that represents time value in nanoseconds.
These three additional types are provided in the java.sql
packages as java.sql.Date, java.sql.Time and java.sql.Timestamp and
are all subclasses of java.util.Date.
Jdbc ppt

More Related Content

What's hot

JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
Information Technology
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
Arati Gadgil
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
Ranjan Kumar
 
Jdbc complete
Jdbc completeJdbc complete
Jdbc complete
Sandeep Rawat
 
1. java database connectivity (jdbc)
1. java database connectivity (jdbc)1. java database connectivity (jdbc)
1. java database connectivity (jdbc)
Fad Zulkifli
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
BG Java EE Course
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
Rohit Jain
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
backdoor
 
Jdbc
JdbcJdbc
Jdbc sasidhar
Jdbc  sasidharJdbc  sasidhar
Jdbc sasidhar
Sasidhar Kothuru
 
DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase Connectivity
Akankshaji
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
hameedkhan2017
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applications
Fulvio Corno
 
JDBC
JDBCJDBC
Advance Java Practical file
Advance Java Practical fileAdvance Java Practical file
Advance Java Practical file
varun arora
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
Dhyey Dattani
 
Database connect
Database connectDatabase connect
Database connect
Yoga Raja
 
JEE5 New Features
JEE5 New FeaturesJEE5 New Features
JEE5 New Features
Haitham Raik
 
Prashanthi
PrashanthiPrashanthi
Jdbc 1
Jdbc 1Jdbc 1

What's hot (20)

JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
Jdbc complete
Jdbc completeJdbc complete
Jdbc complete
 
1. java database connectivity (jdbc)
1. java database connectivity (jdbc)1. java database connectivity (jdbc)
1. java database connectivity (jdbc)
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc sasidhar
Jdbc  sasidharJdbc  sasidhar
Jdbc sasidhar
 
DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase Connectivity
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applications
 
JDBC
JDBCJDBC
JDBC
 
Advance Java Practical file
Advance Java Practical fileAdvance Java Practical file
Advance Java Practical file
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
Database connect
Database connectDatabase connect
Database connect
 
JEE5 New Features
JEE5 New FeaturesJEE5 New Features
JEE5 New Features
 
Prashanthi
PrashanthiPrashanthi
Prashanthi
 
Jdbc 1
Jdbc 1Jdbc 1
Jdbc 1
 

Similar to Jdbc ppt

JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
ChagantiSahith
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
Randy Connolly
 
JDBC Connecticity.ppt
JDBC Connecticity.pptJDBC Connecticity.ppt
JDBC Connecticity.ppt
Swapnil Kale
 
Jdbc
JdbcJdbc
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
Tanmoy Barman
 
Jdbc
Jdbc   Jdbc
Jdbc
Ishucs
 
Mule jdbc
Mule   jdbcMule   jdbc
11. jdbc
11. jdbc11. jdbc
11. jdbc
Rajesh Roky
 
Java JDBC
Java JDBCJava JDBC
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Database
jitendral
 
Jdbc
JdbcJdbc
Jdbc
Ishucs
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
sandeep54552
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
phanleson
 
JDBC
JDBCJDBC
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
Jdbc[1]
Jdbc[1]Jdbc[1]
Jdbc[1]
Fulvio Corno
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
Fulvio Corno
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBC
Dudy Ali
 
Lecture17
Lecture17Lecture17
Lecture17
vantinhkhuc
 
Jsp project module
Jsp project moduleJsp project module

Similar to Jdbc ppt (20)

JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
JDBC Connecticity.ppt
JDBC Connecticity.pptJDBC Connecticity.ppt
JDBC Connecticity.ppt
 
Jdbc
JdbcJdbc
Jdbc
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Jdbc
Jdbc   Jdbc
Jdbc
 
Mule jdbc
Mule   jdbcMule   jdbc
Mule jdbc
 
11. jdbc
11. jdbc11. jdbc
11. jdbc
 
Java JDBC
Java JDBCJava JDBC
Java JDBC
 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Database
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
 
JDBC
JDBCJDBC
JDBC
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
 
Jdbc[1]
Jdbc[1]Jdbc[1]
Jdbc[1]
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
 
Database Connectivity with JDBC
Database Connectivity with JDBCDatabase Connectivity with JDBC
Database Connectivity with JDBC
 
Lecture17
Lecture17Lecture17
Lecture17
 
Jsp project module
Jsp project moduleJsp project module
Jsp project module
 

Recently uploaded

Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
 

Recently uploaded (20)

Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
 

Jdbc ppt

  • 1.
  • 2. JAVA DATABASE CONNECTIVITY Submitted By:- V. Priyanka, II-M.Sc., M. Lavanya, II-M.Sc., S. Suryakala, II-M.Sc., (N. S. College of Arts & Science, Theni, TamilNadu.)
  • 3. JAVA DATABASE CONNECTIVITY JDBC DRIVERS:- The JDBC driver class handles the connection to the database. The java SDK contain only one JDBC driver, a jdbc-odbc bridge that can communicate with an existing open database connectivity(ODBC) driver. Other database need a JDBC driver specific to that database.
  • 4. The jdbc-odbc bridge accepts Uniform Resource Location(URLs)starting with jdbc:odbc: and use the next field in that URL to specify the data source name. The data source name identifiers the particular database scheme you wish to access. There are four type of JDBC drivers:  Type 1 Drivers  Type 2 Drivers  Type 3 Drivers  Type 4 Drivers
  • 5. Type 1 Driver:- Type 1 JDBC drivers are the bridge drivers such as the jdbc- odbc bridge. These drivers rely on an intermediary such as ODBC to transfer the SQL calls to the database. bridge drivers often only one rely on native code. The jdbc-odbc library native cod is part of the java 2 virtual machine.
  • 6. Type 2 Drivers:- Type 2 Drivers use the existing database API to communicate with the database on the client. Although Type 2 drivers are faster than Type 1 drivers use native code and require additional permissions to work in an applet. A Type 2 drivers might need client-side database code to connect over the work.
  • 7. Type 3 drivers:- Type 3 Drivers calls the database API on the server. JDBC requests from the client are first proxied to the JDBC driver on the server to run. This clients can use type 3 and 4 drivers, as they need to native code.
  • 8. Type 4 Drivers:- The highest level of driver reimplements the database network API in the java language. Type 4 Drivers can also be used on thin clients, as they also have no native code.
  • 9. DATABASE CONNECTIONS:- A database connection can be established with a call to the drivermanager.getconnection method. The call takes a URL that identifies the database and optionally, the database login user name and password. Connection con=DriverManager.getconnection (url); Connection con=DriverManager.getconnection (url, “user”, “password” ); After a connection is established, a statement can be run against the database. The result of the statement can be retrieved and the connection is closed.
  • 10. STATEMENTS:- There are three basic types of SQL statements used in the JDBC API. They are Callable Statement Statement Prepared Statement
  • 11. CALLABLE STATEMENTS:- A callable statement is the statement, which lets you execute SQL stored procedure. Once you have established a connection to a database, you can use the connection.prepareCall( ) method to create a callable statement. EX:- Creates a callable Statement object with three parameters for storing account login information. Callable Statement cs= con . prepareCall (“{call accountlogin(?,?,?)}”); cs . setString (1, theuser); cs . setString (2, password); cs.registerOutParameter(3,Types,DATE); cs.executeQuerry( ); Date lastLogin=cs . getdate(3);
  • 12. Statements:- The statement interfere execute a simple SQL statement with no parameters. Query Statement:- This code segment creates a statement object and calls the Statement . executeQuerry( ) method to select text from the dba database. The result of the query are returned in a ResultSet Object. The required result are then retrieved from a ResultSet Object.
  • 13. Example:- Statement stmt = con . createStatement(); ResultSet results = stmt.executeQuery(“SELECT TEXT FROM dba”);
  • 14. Update Statements:- This code segment creates a Statement object and calls the Statement . executeUpdate method to add an email address to a table in the dba database. String updateString = “INSERT INTO dba VALUES(SOME TEXT)”; int count = stmt.executeUpdate(updateString);
  • 15. Prepared Statement:- The PreparedStatement interface descends from the Statement interface and uses a template to create a SQL request. Use a PreparedStatement to send precompiled SQL, statements with one or more parameters. Query Prepared Statement:- This code segment creates a PreparedStatement object to select user data based on the user’s email address. The question mark(“?”)indicates that the statement has one parameter.
  • 16. Example:- PreparedStatement pstmt = con. PreparedStatement(“select The user from registration where email address like ?”); // Initialize first parameter with email address// Pstmt . setString(1,emailAddress); ResultSet results = ps . executeQuerry();
  • 17. Update Prepared Statement:- This code segment creates a PreparedStatement object to update a seller’s registration record. The template has five parameters. PreparedStatement pstmt = con. PreparedStatement(“Insert into registration(theuser, password, email address, creditcard, balance) values ?,?,?,?,?)”); Ps.setString(1,theuser); Ps.setString(2,password); Ps.setString(3,email address); Ps.setString(4,credit card); Ps.setDouble(5,balance); Ps.setUpdate();
  • 18. Caching Data Base Connectivity:- The Prepared Statement concept of reusing requests can be extended for caching the results of a JDBC call. Results Set:- The ResultSet interface managers access to data returned from a query. The data returned, equals one row in a database table. Some queries return only one row of data while many queries return multiple rows of data.
  • 19. Scrolling Result:- JDBC 2.0 introduced scrollable results sets whose values can be read and updated if reading and updating is supported by the underlying database. one advantage to the new result set is you can update a set of matching rows without issuing an additional execute Update call. The updates are made using JDBC calls and so on custom SQL commands need be generated.
  • 20. Controlling Transactions:- JDBC statements are processed in full auto-command mode. This mode works well for a single database query, but if an operation depends on several database statements that all have to completely successfully or the entire operation is cancelled, a finer transaction is needed.
  • 21. To use transaction management in the JDBC platform, you first need to disable the full auto-commit mode by calling: Connection con = getConnection( ); con . setAutoCommit(false); At this point ,you can either commit any following JDBC statements or undo any updates by calling the connection. rollback method. The rollback call is commonly placed in the Exception Handler, although it can be placed anywhere in the transaction flow.
  • 22. Escaping Character:- The JDBC API provide the escape keywords you can specify the character you want to escape characters. EX:- stmt.executeQuery(“select tax from sales where tax like ‘10%’ (escape ‘’)”); To solve this problem, the following method escape any ‘symbol found in the input line’ is used. This method can be extended to escape any other character such as commas, that the database or database driven might interpret another way.
  • 23. Program: static public String escapeLine (String s) { String retvalue = s; if (s. indexOf (“ ‘ ‘ “); !=-1) { StringBuffer hold = new StringBuffer (); char c; for(int i=0; I<s.length (); i++) { hold.append (“ ‘ ‘ “); } else { hold.append(c); } } Retvalue=hold.toString( ); } Return retvalue;}
  • 24. Mapping Data Base Types:- JDBC type such as Integer that are represented as an Integer in most popular database. The JDBC type for a table column does not match the type as it represented in the database. This means calls to ResultSet . getObject, preparedStatement . setobject and callableStatement.getobject()
  • 25. Mapping Date Types The DATE type is where most mismatches occur. This is because the java.util.Date class represents both Date and Time but SQL has the following three types to represent data and time information.  A DATE type that represents the date only (03/23/99)  A TIME type that specifies the time only (12:03:59)  A TIMESTAMP that represents time value in nanoseconds. These three additional types are provided in the java.sql packages as java.sql.Date, java.sql.Time and java.sql.Timestamp and are all subclasses of java.util.Date.