First, let's talk about the bridge connection:
First configure the Data source: Open Control Panel-Administrative Tools-Data Source (ODBC)-user DSN-add-find the Oracle driver.
// JDBC-ODBC Bridge Connection
Public class connectiontest2 {
// Oracledatasource is a local data source
Private Static final string url = "JDBC: ODBC: oracledatasource ";
Private Static final string user = "Scott ";
Private Static final string pass = "admin ";
Public static connection getconnection (){
Try {
// Driver registration driver
Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver"). newinstance ();
Return drivermanager. getconnection (URL, user, pass );
} Catch (exception e ){
E. printstacktrace ();
}
Return NULL;
}
Public static void main (string [] ARGs ){
System. Out. println (connectiontest2.getconnection ());
}
}
JDBC Method
Public class connectiontest {
Private Static final string url = "JDBC: oracle: thin: @ localhost: 1521: orcl ";
// Orcl is the SID 1521oracle port of the database
Private Static final string user = "Scott ";
Private Static final string pass = "admin ";
Public static connection getconnection (){
Try {
Class. forname ("oracle. JDBC. Driver. oracledriver"). newinstance ();
Return drivermanager. getconnection (URL, user, pass );
} Catch (exception e ){
E. printstacktrace ();
}
Return NULL;
}
Public static void main (string [] ARGs ){
System. Out. println (connectiontest. getconnection ());
}
}