About the role of the JDBC Bridge connection mode for a long time, if the wrong place to hope that the great God can point out, thank you very much .... Be sure to point out that ...
Give me a jdbc little chestnut.
Step one: Establish a bridge-connected interface
Public interface Jdbc_api {public
void connection ();
Step Two: Create multiple classes (simulate the classes we initiate the connection) implement the interface
public class MySQL implements JDBC_API {public
void connection () {
System.out.println ("I want to connect to Mysql");
}
public class Oracle implements JDBC_API {public
void connection () {
System.out.println ("I want to connect to Oracle");
}
}
public class DB2 implements JDBC_API {public
void connection () {
System.out.println ("I want to connect to DB2");
}
Step three: Set up abstract class driver (analog manufacturer's connection database), note: Inside to add interface instance object
Public abstract class Driver {
Jdbc_api JDBC;
abstract void createfactory (); Create a database vendor
}
Step four: Build a vendor implementation class
public class Mysqldriver extends Driver {
@Override
void Createfactory () {
System.out.println ("I am a MySQL vendor" );
}
}
public class Oracledriver extends Driver {
@Override
void Createfactory () {
System.out.println (" I am Oracle vendor ");
}
public class Db2driver extends Driver {
@Override
void Createfactory () {
System.out.println ("I am a DB2 manufacturer") ;
}
}
Step five: Establish a test connection Drivermanger
public class DriverManager {public
static void Main (string[] args) {
Driver db=new oracledriver ();
Db.createfactory ();
SYSTEM.OUT.PRINTLN ("------Bridge ODBC-----------");
Db.jdbc=new Oracle ();
Db.jdbc.connection ();
SYSTEM.OUT.PRINTLN ("------Note: Bridge connections can reach multiple locations, not specific oracledriver==>mysql-------");
Db.jdbc=new Mysql ();
Db.jdbc.connection ();
}