Connect Oracle database with JDBC-ODBC Bridge

Source: Internet
Author: User

Using the JDBC-ODBC bridge to connect to the Oracle database and JDBC driver is almost the same, so we don't have to set the environment variable. There are two key statements for connecting to the database in JDBC:

Class. forname ("oracle. JDBC. Driver. oracledriver ");
Connection con = drivermanager. getconnection ("JDBC: oracle: thin: @ 127.0.0.1: 1521: dbname", "username", "password ");

Similarly, bridge connections are the two statements, but the drive and method have changed, as shown below:

Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver ");
Connection con = drivermanager. getconnection ("JDBC: ODBC: userdsn", "username", "password ");

Userdsn must be configured in the ODBC source to test the complete connection.ProgramSee:

Import Java. SQL. *;
public class jdbc_odbc
{< br> Public static void main (string [] ARGs)
{< br>
connection conn;
try
{< br> class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver ");
}< br> catch (exception e)
{< br> system. out. println ("Driver exception! ");
}< br> try
{conn = drivermanager. getconnection ("JDBC: ODBC: User", "Scott", "Tiger");
system. out. println ("connect to the database normally. ");
}< br> catch (sqlexception e)
{< br> system. Out. println (" connection error! ");
}< br>
}< BR >}

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.