Presentation is loading. Please wait.

Presentation is loading. Please wait.

ODBC and JDBC What are they – libraries of function calls that support SQL statements Why do we need them –Provide a way for an application to communicate.

Similar presentations


Presentation on theme: "ODBC and JDBC What are they – libraries of function calls that support SQL statements Why do we need them –Provide a way for an application to communicate."— Presentation transcript:

1 ODBC and JDBC What are they – libraries of function calls that support SQL statements Why do we need them –Provide a way for an application to communicate with a database Why are they good –interoperability

2 ODBC (Open Database Connectivity) Application Driver Manager ODBC interface Driver A Driver B Driver C DS ADS B DS C

3 Adding an ODBC source Purpose: register a data source How-to (Windows 2000) –Start->Settings->Control Panel-> Administrative Tools->Data Sources(ODBC) NB: You need to register a new SQL server before you create the DSN

4 Further steps…. Select the System DSN tab Click add and choose SQL server (usually the bottom driver listed). Click Finish.

5 Further steps…. Chose identification entered by the user. Note: this is not the default option, so pay attention Enter the ID and password I gave you Agree with everything else in the wizard Test the data source and if your test succeeds, hit OK

6 JDBC (Java Database Connectivity) What is it: –Java classes that allow an app to communicate with a database Three types of JDBC drivers: –Proprietary –Bridge Drivers (e.g. JDBC-ODBC) –JDBC-Net

7 How does it work JDBC-ODBC bridge ODBC driver So, how does it work? You need to load the bridge driver and get a connection from the driver manager

8 Confusing? Let’s look at some code import java.sql.*; Class FirstTry{ public static void main(String[] args){ try{ String url=“jdbc:odbc:myDSN”; /*load the driver from Sun.Even if you don’t understand this, this line is always the same*/ Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); //get a connection Connection con=DriverManager.getConnection(url,”userID”,”password”); }catch….

9 How does it fit together Note the DSN in the database url—it is the ODBC DSN JDBC is just a way for Java applications to do what ASP does with ODBC.

10 What next Well, just have fun. Check out Sun’s API for the sql package http://java.sun.com/j2se/1.3/docs/api/index.html http://java.sun.com/j2se/1.3/docs/api/index.html See Sun’s tutorial on JDBC http://java.sun.com/tutorial

11 The Front End Web pages: static/dynamic Techniques for creating dynamic content : –CGI (Perl), ASP, JSP Requests, Responses and Headers –HTTP: simple, stateless. Client(I.e.browser) requests, web server responds Requests can be of several types(methods): usually GET and POST

12 ADO Set of objects to modify and access data through OLE DB interface: Connection, Command,Recordset,Error Application uses ADO which talks to OLE DB provider for ODBC, which loads the right ODBC driver. Note: providers represent diverse sources of data, pick the right one


Download ppt "ODBC and JDBC What are they – libraries of function calls that support SQL statements Why do we need them –Provide a way for an application to communicate."

Similar presentations


Ads by Google