Import java. SQL .*;
Public class ora8iconnect
{
Public ora8iconnect (string dB, string ID, string PWD)
{Dbname = dB;
Userid = ID;
Userpwd = PWD;
Beginconnect (); // connect to the database
}
/*-
* Returns a connection object.
*/
Public connection getconnection () {return conn ;}
/*-
* Connect to the database. If the connection succeeds, 1 is returned. Otherwise, 0 is returned.
*/
Public int beginconnect ()
{Try
{// Load an oracle driver
Drivermanager. registerdriver (New Oracle. JDBC. Driver. oracledriver ());
// Use oci8 to connect to the database
Conn = drivermanager. getconnection ("JDBC: oracle: oci8: @" + dbname, userid, userpwd );
Return 1;
}
Catch (sqlexception e) // capture SQL violations
{System. Out. println ("captured when ora8iconnect connects to the oracle8 Database ");
While (E! = NULL)
{System. Out. println ("sqlstate:" + E. getsqlstate ());
System. Out. println ("message:" + E. getmessage ());
System. Out. println ("vendor:" + E. geterrorcode ());
E = E. getnextexception ();
System. Out. println ("");
}
Conn = NULL;
Return 0;
}
}
Private connection conn; // connection object
Private string dbname; // instance
Private string userid; // User Name
Private string userpwd; // Password
}