Re: connecting to an oracle db using the thick (oci) driver

From: Dave Holland (dholland_at_mgtplc.com)
Date: 06/29/04


Date: 29 Jun 2004 05:21:09 -0700


"Robert A.M. van Lopik" <lopik@mail.telepac.pt> wrote in message news:<2kaullF4momU1@uni-berlin.de>...
> "Dave Holland" <dholland@mgtplc.com> wrote in message
> news:28e02f94.0406250515.11bf4d60@posting.google.com...
> > Hi,
> > I hope someone out there can help me with this. I usually connect to
> > the oracle database from my java code via the thin driver. However I
> > have been asked to investigate using the oci driver instead. I have
> > installed the oracle 9 client (on my win2000 PC) and have set up a
> > test harness (code below), but all I seem to get is a
> > 'java.sql.SQLException: Closed Connection' when I try to connect.
> >
> > code follows>>>>>
> > import java.sql.*;
> >
> > public class DbHarness{
> > public static void main(String [] args){
> > DbHarness thisTest = new DbHarness();
> > thisTest.test();
> > //thisTest.connect();
> > }
> > public void DbHarness(){}
> >
> > public void test(){
> > System.out.println("about to connect");
> > connect();
> > System.out.println("Connection complete");
> >
> > }
> > public void connect(){
> > Connection conn = null;
> > try {
> > Class.forName("oracle.jdbc.driver.OracleDriver");
> > String connectString = "jdbc:oracle:oci:@BOB";
> > conn = DriverManager.getConnection(connectString,
> > "bobuser", "bobpassword");
> > if (conn!=null){
> > System.out.println("connection made");
> > }
> > else{
> > System.out.println("connection NOT made");
> > }
> > }
> > catch(ClassNotFoundException cnfe) {
> > System.err.println(cnfe);
> > }
> > catch(SQLException sqle) {
> > System.err.println("error connecting to db "+
> > sqle.toString()); //error connection to database
> > sqle.printStackTrace();
> > }
> > finally{
> > if (conn!=null){
> > try{
> > conn.close();
> > }
> > catch(SQLException e){
> > System.err.println("can't close connection
> > "+e.toString());
> > }
> > }
> > }
> > }
> > }
> >
> > //end code
> > where BOB is the tnsnames.ora file entry for my database and bobuser
> > is the user name and bobpassword is the password
> >
> > full output is
> > about to connect
> > error connecting to db java.sql.SQLException: Closed Connection
> > java.sql.SQLException: Closed Connection
> > at
> oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
> > at
> oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
> > at oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:2348)
> > at oracle.jdbc.oci8.OCIDBAccess.logon(OCIDBAccess.java:477)
> > at
> oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:346)
> >
> > at
> oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
> > va:468)
> > at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
> > at java.sql.DriverManager.getConnection(Unknown Source)
> > at java.sql.DriverManager.getConnection(Unknown Source)
> > at DbHarness.connect(DbHarness.java:26)
> > at DbHarness.test(DbHarness.java:13)
> > at DbHarness.main(DbHarness.java:6)
> > Connection complete
> >
> >
> > Thanks in advance
> > Dave Holland
>
> I only wrote jdbc code once and what I have looks like:
>
> try
> {
> DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
>
> Connection conn =
> DriverManager.getConnection ("jdbc:oracle:oci8:@connectstring", dbUser,
> dbPw);
> ...
> and that works. Did you make sure you can logon to the database using that
> connect string in SQLplus?
>
> hth
>
> rob van lopik

Hi,
Both DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver()); and
Class.forName("oracle.jdbc.driver.OracleDriver"); can be used to
register the driver, the 'DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver())' way tends to be used in non-JDK
JVMs such as Microsofts. I've not yet worked out where the problem
is. I suspect it could be in my install of the oracle client, I'll
pursue this and post what I find.
Dave Holland



Relevant Pages

  • Importing Oracle Driver to JBuilder project
    ... It was difficult to find out the driver to connect to Oracle database ... I am a beginner with Java and JSP. ...
    (comp.lang.java.databases)
  • Re: Cannot display ODBC login prompt - want to connect without DSN
    ... database without knowing anything beforehand except the driver name. ... need a connection string and different data sources use different connection ... ODBC, ADO, and VB Script. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: JDBC URL for Oracle Database With Failover (2 db servers)
    ... After you've loaded the driver, you can establish a connection using ... each form requires a database URL. ... For Oracle, the database URL has ...
    (comp.lang.java.databases)
  • RE: New JDBC 1.2 driver runs slower than JDBC 1.1; my db definitio
    ... If the support incident ends up verifying a slowdown in the new driver, ... New JDBC 1.2 driver runs slower than JDBC 1.1; ... I do think this would happen in general, not just for my database; ...
    (microsoft.public.sqlserver.jdbcdriver)
  • RE: Import external data - web query
    ... Your reply for my query is very extensive, this is for importing a file from ... The data source I want isn't listed in the Select Data Source dialog box. ... information used to connect to a database. ... Check your driver First, make sure you have the right ODBC driver (Open ...
    (microsoft.public.excel.misc)