 JDBC – provides an interface to
Relational Data Sources.
 JDBC library provides the means for
executing SQL statements ...
 JDBC:
 establishes a
connection with a
database
 sends SQL statements .
 processes the results.
Java Application
JDBC
Access
Database
Oracle
Database
Sybase
Database
 JDBC’s DEsIGn Is vEry sImIlar to tHE
design of ODBC.
 Driver Manager
 Loads database drivers, and
manages the connecti...
 Statement
 An SQL Statement to perform a
query or update operation.
 Metadata
 Information about returned
data, the d...
Driver
Manager
Connection Statement ResultSet
Driver
Database
Creates Creates Creates
SQL
Result
(tuples)
Establish
Link t...
 Java Application
talks directly to
the database.
 Accomplished
through the JDBC
driver which
sends commands
directly to...
 JDBC driver sends
commands to a middle
tier, which in turn
sends commands to
database.
 middle tier can
provide
• a hig...
Application Space
Java Application
JDBC Driver
Database
SQL
Command
Result
Set
Application Server
(middle-tier)
Proprietar...
JDBC API, a purely
java-based API.
JDBC Driver Manager
which communicates
with vendor specific
drivers that perform
real...
 JDBC-ODBC bridge
plus ODBC driver
basically converts
JDBC calls to
mICrosoFt’s opEn
database
connectivity(ODBC).
 As wi...
Advantages:
• Can be useful for databases
where other methods not
available (e.g., MSAccess).
Disadvantages:
• Client comp...
SQL Type Java Type
CHAR String
VARCHAR String
LONGVARCHAR String
NUMERIC
java.Math.BigDecimal
DECIMAL
java.Math.BigDecimal...
1. Importing Packages .
2. Registering the JDBC Drivers .
3. Opening a Connection to a
Database .
4. Creating a Statement ...
// Program name: jdbc_smvdu.java
//Import packages
import java.sql.*; // JDBC
packages
import java.math.*;
import java.io....
class jdbc_smvdu {
public static void main (String args [])
throws SQLException {
// Load Odbc driver
Class.forName(“sun.j...
//Prompt user for username and password
String user;
String password;
user = readEntry
("username: ");
password = readEntr...
Statement stmnt=
conn.createStatement();
String st= “sElECt FIrst namE, aGE
From EmployEE wHErE ID= 20 ”;
ResultSet rset =
stmnt.executeQuery (s);
// Print query results
while (rset.next ())
System.out.println (rset.getString
(1...
// close the result set, statement, and the
connection
rset.close( );
stmnt.close( );
conn.close( );
}
Rajesh   jdbc
Rajesh   jdbc
Upcoming SlideShare
Loading in...5
×

Rajesh jdbc

263

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
263
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Rajesh jdbc

  1. 1.  JDBC – provides an interface to Relational Data Sources.  JDBC library provides the means for executing SQL statements to access and operate on a relational database.  JDBC library is implemented in the java.sql package  Set of classes and interfaces that provide a uniform API for access to broad range of databases.
  2. 2.  JDBC:  establishes a connection with a database  sends SQL statements .  processes the results.
  3. 3. Java Application JDBC Access Database Oracle Database Sybase Database
  4. 4.  JDBC’s DEsIGn Is vEry sImIlar to tHE design of ODBC.  Driver Manager  Loads database drivers, and manages the connection between the application and the driver.  Driver  Translates API calls into operations for a specific data source
  5. 5.  Statement  An SQL Statement to perform a query or update operation.  Metadata  Information about returned data, the database and the driver.  ResultSet  Logical set of columns and rows returned by executing an SQL statement (resulting tuples).
  6. 6. Driver Manager Connection Statement ResultSet Driver Database Creates Creates Creates SQL Result (tuples) Establish Link to DB
  7. 7.  Java Application talks directly to the database.  Accomplished through the JDBC driver which sends commands directly to the database.  Results sent back directly to the application.  A JDBC driver sits on the client Application Space Java Application JDBC Driver Database SQL Command Result Set
  8. 8.  JDBC driver sends commands to a middle tier, which in turn sends commands to database.  middle tier can provide • a higher-level API, not just SQL • control over database access • performance advantages ex. load balancing and caching frequently accessed data Application Space Java Application JDBC Driver Database SQL Command Result Set Application Server (middle-tier) Proprietary Protocol
  9. 9. Application Space Java Application JDBC Driver Database SQL Command Result Set Application Server (middle-tier) Proprietary Protocol Pros: flexible: can change one part without affecting others can connect to different databases without changing code specialization: presentation / business logic / data management can cache queries can implement proxies and firewalls Cons: higher complexity higher maintenance lower network efficiency
  10. 10. JDBC API, a purely java-based API. JDBC Driver Manager which communicates with vendor specific drivers that perform real communication with the database. Java Application JDBC Driver Manager JDBC/ODBC Bridge Vendor Supplied JDBC Driver ODBC Driver
  11. 11.  JDBC-ODBC bridge plus ODBC driver basically converts JDBC calls to mICrosoFt’s opEn database connectivity(ODBC).  As with JDBC , ODBC programming interface that you can use to access Application Space Java Application JDBC – ODBC Bridge Database SQL Command Result Set ODBC Driver Proprietary Protocol
  12. 12. Advantages: • Can be useful for databases where other methods not available (e.g., MSAccess). Disadvantages: • Client computer needs to be configured with ODBC driver and ODBC instance which specifies database server and other
  13. 13. SQL Type Java Type CHAR String VARCHAR String LONGVARCHAR String NUMERIC java.Math.BigDecimal DECIMAL java.Math.BigDecimal BIT boolean TINYINT int SMALLINT int INTEGER int BIGINT long REAL float FLOAT double DOUBLE double BINARY byte[] VARBINARY byte[] DATE java.sql.Date
  14. 14. 1. Importing Packages . 2. Registering the JDBC Drivers . 3. Opening a Connection to a Database . 4. Creating a Statement Object. 5. Executing a Query and Returning a Result Set Object . 6. Processing the Result Set . 7. Closing the Result Set and Statement Objects .
  15. 15. // Program name: jdbc_smvdu.java //Import packages import java.sql.*; // JDBC packages import java.math.*; import java.io.*; import oracle.jdbc.driver.*;
  16. 16. class jdbc_smvdu { public static void main (String args []) throws SQLException { // Load Odbc driver Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
  17. 17. //Prompt user for username and password String user; String password; user = readEntry ("username: "); password = readEntry ("password: "); // Connect to the local database Connection conn = DriverManager.getConnection
  18. 18. Statement stmnt= conn.createStatement(); String st= “sElECt FIrst namE, aGE From EmployEE wHErE ID= 20 ”;
  19. 19. ResultSet rset = stmnt.executeQuery (s); // Print query results while (rset.next ()) System.out.println (rset.getString (1)+" "+ rset.getString(2));
  20. 20. // close the result set, statement, and the connection rset.close( ); stmnt.close( ); conn.close( ); }
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×