Your SlideShare is downloading. ×
0
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
Database
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

Database

939

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Database <ul><ul><li>Collection of Tables which are collection of Records </li></ul></ul>Relational Database <ul><li>Tables are related. </li></ul><ul><li>Operations on one table can be made to affect another table by using Referential Integrity. </li></ul>
  • 2. RDBMS <ul><li>Collection of several relational databases </li></ul>(Ex) Oracle Server SQL Server DB2 Server
  • 3. SQL <ul><li>SQL commands are used to speak to RDBMS Servers. </li></ul><ul><li>Using common SQL commands, all these servers could be contacted. </li></ul>(EX) Select * from table where &lt;condition&gt; Update table set field= &lt;values&gt; where &lt;condition&gt; Insert into table(field1,field2..) values (value1,value2...) Delete from table where fieldname=value
  • 4. Remote Database Access User Database Client API Database Server Database VC++,VB Java programs ODBC or JDBC For different databases, database client need not talk in different ways.Database client talks through ODBC API or JDBC API and the API talks to the database server.Database Server listens to a port and responds only to SQL commands passed by ODBC or JDBC.
  • 5. JDBC versus ODBC <ul><li>ODBC is a C language API, not a Java API. Java is object oriented and C is not. C uses pointers and dangerous programming constructs that Java does not support. </li></ul><ul><li>ODBC drivers must be installed on client machines. This means that the Applet that has to access to databases needs a driver in the client side. If the driver is a ODBC driver, the applet does not execute. </li></ul><ul><li>A Pure Java solution allows JDBC drivers to be automatically installed along with the applet. </li></ul>
  • 6. JDBC Driver Types 1. JDBC-ODBC bridge plus ODBC driver 2. Native-API partly-Java driver 3. JDBC-Net pure Java driver 4. Native-protocol pure Java driver
  • 7. 1.JDBC-ODBC bridge plus ODBC driver: This driver uses Microsoft’s ODBC driver to communicate with Database servers. It is an attempt to use the existing ODBC drivers. It is implemented using C and Java and must be preinstalled on a client computer before it can be used. JDBC Driver Types
  • 8. Database Client JDBC ODBC Bridge Oracle Server DB2 SQL Server ODBC ODBC ODBC JDBC
  • 9. 2. Native-API partly-Java driver: These drivers talks to database servers in a server’s native protocol. There are certain C language libraries for connecting to Oracle , DB2 or any other database. This driver will use those C language libraries for speaking with the particular database. These drivers are implemented in a combination of binary code in Java and must be installed on a client machine.
  • 10. Database Client Native partly Java driver Database Server Vendor specific protocol
  • 11. 3. JDBC-Net pure Java driver: This driver translates JDBC calls into a DBMS- independent net protocol (HTTP) which is then translated to a DBMS protocol by a server. This net server middleware is able to connect its pure Java clients to many different databases. The specific protocol used depends on the vendor. This is the best solution for applets which wants to talk to database directly without using servlets.
  • 12. Database access server Pure Java driver Database Client Oracle Server DB2 server SQL server
  • 13. 4. Native-protocol pure Java driver: This driver category consists of pure Java driver that uses vendor specific database protocol of the database server directly.
  • 14. Database Client Pure Java driver Database Server Vendor specific protocol
  • 15. <ul><li>The acronym for JDBC does not exactly stands for Java Database Connectivity but is referred by that name </li></ul>JDBC What Does JDBC Do? JDBC makes it possible to do three things: · establish a connection with a database · send SQL statements · process the results.
  • 16. The following code fragment gives a basic example of these three steps: Connection con = DriverManager.getConnection ( &amp;quot;jdbc:odbc:wombat&amp;quot;, &amp;quot;login&amp;quot;, &amp;quot;password&amp;quot;); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(&amp;quot;SELECT a, b, c FROM Table1&amp;quot;); while (rs.next()) { int x = rs.getInt(&amp;quot;a&amp;quot;); String s = rs.getString(&amp;quot;b&amp;quot;); float f = rs.getFloat(&amp;quot;c&amp;quot;); }
  • 17. The standard syntax for JDBC URLs is shown below. It has three parts, which are separated by colons: jdbc:&lt;subprotocol&gt;:&lt;subname&gt;
  • 18. Driver Manager The DriverManager class is the management layer of JDBC, working between the user and the drivers. It keeps track of the drivers that are available and handles establishing a connection between a database and the appropriate driver.
  • 19. Steps for connecting database <ul><li>1. Loading the Driver </li></ul><ul><li>Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); </li></ul><ul><li>2. Constructing URL for the database. </li></ul><ul><li>String url=“jdbc:odbc:dsn”; </li></ul><ul><li>3. Getting the Connection. </li></ul><ul><li>Connection con=DriverManager.getConnection(url,userid,pwd); </li></ul>
  • 20. <ul><li>4. Creating the statement </li></ul><ul><li>Statement stmt=con.createStatement(); </li></ul><ul><li>5. Execute the corresponding SQL statements. </li></ul><ul><li>ResultSet rs=stmt.executeQuery(“select * from Table where empno=5”); </li></ul><ul><li>6. Reading the values from the Resultset. </li></ul><ul><li>while(rs.next()) </li></ul><ul><li>{ </li></ul><ul><li>String s=rs.getString(“empname”); </li></ul><ul><li>double sal=rs.getDouble(“empsal”); </li></ul><ul><li>} </li></ul>
  • 21. execute(),executeUpdate(),executeQuery <ul><li>executeQuery()--- used to execute only SQL query statements </li></ul><ul><li>executeUpdate()--- used to execute either insert, update or delete statements </li></ul><ul><li>execute()--- used to execute any type of statements like insert, update, delete or select statements </li></ul>
  • 22. How to use execute() statement <ul><li>boolean hasresults=stmt.execute(“select statement”); </li></ul><ul><li>if(hasresults){ </li></ul><ul><li>ResultSet rs=stmt.getResultSet( ); </li></ul><ul><li>String str=rs.getString(“empnam”); </li></ul><ul><li>. </li></ul><ul><li>. </li></ul><ul><li>} </li></ul>
  • 23. DatabasemetaData &amp; ResultSetMetaData interfaces <ul><li>DatabaseMetaData interface has methods that are used to identify the database configuration </li></ul><ul><li>ResultSetMetaData interface has methods that are used to identify the database configuration </li></ul>

×