JDBC's first ...

zhaozj2021-02-16  205

JDBC is a Java API for executing a SQL statement, which consists of a class and interface written in Java language, and JDBC provides a group of standard APIs for several years.

The JDBC interface is divided into two levels, one is the JDBC API for programmer, and the other is the underlying JDBC Driver API.

JDBC API ======== JDBC API is a series of abstract interfaces that make the developers of the JSP program to connect, execute SQL statements, and return results. These interfaces include:

Java.sql.driverManager Processes the driven transfer and supports the generated database connection.

Java.sql.connection represents the connection to a specific database to complete the connection function of a specified database;

Java.sql.Statement represents a container to perform SQL statements for a specific database;

Java.sql.ResultSet Access to the row data of a specific statement;

There are two subtypes in java.sql.statement:

Java.sql.preparedStatement is used to perform pre-compiled SQL statements

Java.sql.calLableStatement is used to perform calls to the embedded process of a database.

JDBC Driver API ============ is an interface for driver developers. For most database drivers, only the abstract interface of the JDBC API is enough.

JDBC driver type ==================

>> JDBC-ODBC bridge plus ODBC driver

Realize the JDBC operation to an ODBC operation. Therefore, this method can be utilized to achieve and most of the database system connection. Bridge driver class is sun.jdbc.odbc.jdbcodbcdriver example:

<% @ Page Import = "java.sql. *"%>

<% Try {string URL = new string (); URL = "JDBC: ODBC: TEST";%> <% - load JDBC-ODBC Bridge driver -%> <% class.forname ("Sun.jdbc. odbc.jdbcodbcdriver ");%> <% - Try to establish a connection to the data source specified by the URL -%> <% connection con = drivermanager.getConnection (URL);%>} catch (sqlexception e) {...} %>

>> Local API

This type of driver converts JDBC on the client API to Orcal, Informix, etc. calls.

>> JDBC Network Pure Java Driver

It belongs to a relatively flexible JDBC driver, which is converted to a network protocol that is independent of DBMS, and then converts it to another DBMS protocol after a server. This network server middleware can receive its pure Java client on a variety of different databases.

>> Local Agreement Pure Java Driver

Directly converted to the network protocol used by DBMS, which will allow DBMS servers directly on the client machine to be a very practical solution for Internet access.

** Use JDBC-ODBC to connect other database ========================================= Connect to Oracle

<% Class.Forname ("Oracle.jdbc.driver.OracleDriver"). NewInstance ();

String Url = "JDBC: Oracle: Thin: @localhost: 1521: Orcl";

// orcl for your database SID

String User = "fly29";

String password = "fly29";

Connection conn = drivermanager.getConnection (URL, User, Password);

%>

>> Connect to SQL Server7.0 / 2000

<% Class.Forname ("com.microsoft.jdbc.sqlser.sqlserverdriver). Newinstance ();

String Url = "JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = PUBS";

// Pubs for your database

String User = "sa";

String password = ""

Connection conn = drivermanager.getConnection (URL, User, Password);%>

>> Connect to DB2

<% Class.forname ("com.ibm.db2.jdbc.app.db2driver"). NewInstance ();

String Url = "JDBC: DB2: // LocalHost: 5000 / Sample";

// Sample is your database name

String user = "admin";

String password = ""

Connection conn = drivermanager.getConnection (URL, User, Password);%>

>> Connect to MySQL

<% Class.forname ("org.gjt.mm.mysql.driver"). NewInstance ();

String url = "jdbc: mysql: // localhost / softforum? User = Soft & password = SOFT1234 & UseUnicode = True & Characterencoding = 8859_1"

// testdb names for your database

Connection conn = drivermanager.getConnection (URL);%>

>> Connect to Access <% String Url = "JDBC: ODBC: driver = {MicrosoftAccessDriver (*. MDB)}; DBQ = Books.mdb"; Class.Forname ("Sun.jdbc.odbc.jdbCodbcdriver");

转载请注明原文地址:https://www.9cbs.com/read-9148.html

New Post(0)