Transcript odbc

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
ODBC
(Open Database Connectivity)
Application
ODBC interface
Driver Manager
Driver
A
DS A
Driver C
Driver
B
DS B
DS C
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
Further steps….
• Select the System DSN tab
• Click add and choose SQL server (usually
the bottom driver listed). Click Finish.
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
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
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
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….
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.
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
• See Sun’s tutorial on JDBC
http://java.sun.com/tutorial
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
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