Your SlideShare is downloading. ×
Rajesh   jdbc
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Rajesh jdbc


Published on

Published in: Technology

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 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.  JDBC:  establishes a connection with a database  sends SQL statements .  processes the results.
  • 3. Java Application JDBC Access Database Oracle Database Sybase Database
  • 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.  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. Driver Manager Connection Statement ResultSet Driver Database Creates Creates Creates SQL Result (tuples) Establish Link to DB
  • 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.  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. 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. 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.  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. 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. 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. 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. // Program name: //Import packages import java.sql.*; // JDBC packages import java.math.*; import*; import oracle.jdbc.driver.*;
  • 16. class jdbc_smvdu { public static void main (String args []) throws SQLException { // Load Odbc driver Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
  • 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. Statement stmnt= conn.createStatement(); String st= “sElECt FIrst namE, aGE From EmployEE wHErE ID= 20 ”;
  • 19. ResultSet rset = stmnt.executeQuery (s); // Print query results while ( ()) System.out.println (rset.getString (1)+" "+ rset.getString(2));
  • 20. // close the result set, statement, and the connection rset.close( ); stmnt.close( ); conn.close( ); }