Case study of connecting Oracle with Java

Source: Internet
Author: User

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 ());
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.