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