Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

78 views
Skip to first unread message

Dave Holland

unread,
Jun 25, 2004, 9:15:07 AM6/25/04
to
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

Robert A.M. van Lopik

unread,
Jun 28, 2004, 12:08:36 PM6/28/04
to

"Dave Holland" <dhol...@mgtplc.com> wrote in message
news:28e02f94.04062...@posting.google.com...

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

Dave Holland

unread,
Jun 29, 2004, 8:21:09 AM6/29/04
to
"Robert A.M. van Lopik" <lo...@mail.telepac.pt> wrote in message news:<2kaull...@uni-berlin.de>...


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

Shanmuhanathan T

unread,
Jul 8, 2004, 8:11:31 AM7/8/04
to
on 6/25/2004 6:45 PM Dave Holland Wrote:
> 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>>>>>
<snip>

> 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

Dave,
The only time I got this error was when my JDBC class versions did not
match the OCI version - specifically I was using JDBC with Jdeveloper10g
to connect using OCI in my 9i oracle_home. Sync'ing up the JDBC/OCI
versions should solve this problem.
--
Shanmu

K N V Sudhakar

unread,
Jul 16, 2004, 3:05:02 AM7/16/04
to
Hi Dave,

I am also getting the same/similar message when I am trying to connect
to Oracle database.

I am able to connect to the database if I add the connection string
put in tnsnames.ora in the statement as mentioned below:
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@(description=(address=(
host=10.8.32.178)(protocol=tcp)(port=1521))(connect_data=(sid="+BCVDatabase+")))",BCV_user,
BCV_password);

But when I am using the statement as below
Connection conn = DriverManager.getConnection("jdbc:oracle:oci:@VLCTYPOC",
BCV_user, BCV_password);
and adding connection String for VLCTYPOC in TNSNAMES.ora, I am
getting the error message as java.sql.SQLException: Closed Connection.

Shanmuhanathan T <shan...@mailinator.com> wrote in message news:<v0bHc.18$kO4...@news.oracle.com>...

0 new messages