Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
JDBC Overview
Stands for Java Database Connectivity A standard interface for accessing data sources normally databases (works with Excel) A base for building higher level tools and APIs
JDBC Overview
Defined by
interfaces and classes in the java.sql package
Implemented by
data source specific JDBC drivers
accept JDBC calls and perform operations using the API of the specific database
JDBC Overview
Databases are specified with URL syntax
What is ODBC?
Translating ODBC into pure Java would be difficult due to its heavy use of pointers ODBC is harder to learn than JDBC
complex, rarely used operations coexist with common ones must learn a lot in order to use basic functionality with JDBC, uncommon operations are supported by separate interfaces from those that provide basic functionality
5
JDBC Overview
Design of JDBC
based on ODBC and the
X/OPEN SQL Call Level Interface
JDBC-ODBC Bridge
allows access to ODBC databases from Java applications
JDBC Architecture
When Java code requests a data source connection the DriverManager chooses the appropriate registered driver
determined from subprotocol in URL specification
ex. jdbc:odbc:MySource
10
JDBC API
11
Loading drivers
Connection
Connection
Establishing connections
Statement
Statement
Statement
Statement
ResultSet
ResultSet
ResultSet
ResultSet
12
Establishing connections
Creating and executing statements
Processing ResultSet
For MySQL:
Connection connection = DriverManager.getConnection ("jdbc:mysql://localhost/test");
For Oracle:
Connection connection = DriverManager.getConnection ("jdbc:oracle:thin:@liang.armstrong.edu:1521:orcl", "scott", "tiger");
14
Creating statement:
Statement statement = connection.createStatement();
15
Processing ResultSet
16