Use JDBC to connect to the Oracle database (the problem can be solved. I would like to summarize it. Thank you)

Source: Internet
Author: User
Tags getmessage odbc odbc connection oracle database
There are usually four connection methods to choose from. Here I only use two of them
I use tomcat under win98
The server is winnt and Oracle is installed
My class path is: D: omcatwebappsROOTWEB-INFclassesyourpackage
Jsp path: D: omcatweb‑root
Call path: http: // 127.0.0.1: 8080/connOracle. jsp
(You can't do it. You can try my path ^_^)
1. Use the JDBC_ODBC bridge to connect
First, remember to create an ODBC Connection in the system data source. ^ _ ^ (you can use PB or other programs to connect to the database and test whether the ODBC is successfully established)
Next, you can write a class file using the following class files:
Package yourpackage; // note that java class storage systems are related to file systems :)
Import java. SQL .*;
Public class opendb
{
String sDBDriver = "sun. jdbc. odbc. JdbcOdbcDriver ";
String sConnStr = "jdbc: odbc: yourdb"; // yourdb here is the original DNS of your ODBC data
Connection conn = null;
ResultSet rs = null;
Public opendb ()
  {
Try {
Class. forName (sDBDriver );
    }
Catch (java. lang. ClassNotFoundException e)
    {
System. err. println ("opendb ();" + e. getMessage ());
    }
  }
Public ResultSet executeQuery (String SQL)
  {
Rs = null;
Try {
Conn = DriverManager. getConnection (sConnStr, "username", "password"); // note that the database username and password must be set according to the actual situation.
Statement stmt = conn. createStatement ();
Rs1_stmt.exe cuteQuery (SQL );
    }
Catch (SQLException ex ){
System. err. println ("aq.exe cuteQuery:" + ex. getMessage ());
Related Article

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.