wood burning stoves 2.0*
The moose likes JDBC and the fly likes Connecting to DB Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connecting to DB Error" Watch "Connecting to DB Error" New topic
Author

Connecting to DB Error

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Hi Everyone,

I am trying to connect to DB (Oracle 10g) through a Java code. Please take a look at the code:




But the problem is i am getting an error while connecting to the database:




Could you please tell me what's the problem here?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


[Microsoft][ODBC Driver Manager]

Looks like you are trying to use the JDBC-ODBC bridge. I can't see that anywhere in the code you've posted (unless its in BBADataPurger?) so you are maybe not running the code you think you are.

That being said, the code you are trying to run seems to be trying to use a DataSource, not a Driver, which won't work. Also, are you intending to use the XA driver?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Hi.

You are mixing up the oracle jdbc driver and the Sun jdbcodbc bridge.

This point out that you want to use Oracle jdbc driver:
oracle.jdbc.xa.client.OracleXADataSource

and this is a mix between jdbcodbc and Oracle jdbc url:
jdbc:odbc:thin@10.10.34.11:1522:CAP

Regards, Jan

[Paul types faster]


OCUP UML fundamental and ITIL foundation
youtube channel
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
So what changes do i have to make here? Should i change this:

or

I am trying to connect to a database which is on the server from my local system. Its a strandalone java class.
Complete class is:
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

You can find both the neccessary driver class info and the url instructions at Oracle.
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Is using an XA an advisale way to go about this?

I changed my code to:


and now i get the error:
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Somnath Mallick wrote:....
and now i get the error:

Solution on same url as in my previous post.
Look for: Installation
How do I install the Thin driver?
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
The solution given:
How do I install the Thin driver?
Put the jar files in a convenient location and include the appropriate jar files in your classpath. See What are all these files for? to determine which files you need.


I have ojdbc14.jar and classes12.jar added in my classpath already. Are there any more jars to be added. I checked the list given in your link. All are different version of the two jars i already have!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Only put the correct .jar in the classpath.

Class.forName("oracle.jdbc.xa.client.OracleXADataSource");
How sure are you about this part of your code?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Those are very old versions of the driver - are you running a 1.4 JDK or below? If not you'll need the correct files (see Jan's link)

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Pretty much sure. Because i used this many times in other places where i was able to connect and work on DB's.
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Paul Sturrock wrote:Those are very old versions of the driver - are you running a 1.4 JDK or below? If not you'll need the correct files (see Jan's link)


Could you please let me know what are the latest versions of the jar? I have to catch a flight in 2 hours. and i am already running late. I will download them when i get home!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Somnath Mallick wrote:Pretty much sure. Because i used this many times in other places where i was able to connect and work on DB's.


Its odd to see someone load a DataSource this way. More normally you would register a Driver with the DriveManager not a DataSource. And using the XA tends to be the exception rather than the rule. Do you need an XA driver?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Somnath Mallick wrote:
Could you please let me know what are the latest versions of the jar? I have to catch a flight in 2 hours. and i am already running late. I will download them when i get home!


I'm not sure I could answer this any better than Oracle do in Jan's link. Have a read of those FAQs.
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Could you please show me an example which shows a proper way of getting data from a DataSource. I have loaded XA drivers this way in quite a few codes and they all worked without any issues.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

I'm getting a bit lost.
Do you still have issues with the original code from the first post?
Or is the original code now working, and do you want to go a step further?

Regards, Jan
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
The code is not working!

And would definitely like a step further!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

What if you take a brand new start?

- get the correct version of the jar file for matches your database version, and stop using any other Oracle JDBC .jar
- register the correct driver. (see also the linc toOracle basic instructions below.
- use the correct url to connect to your Oracle database.
- test.

Oracle's First Steps in JDBC.

I have loaded XA drivers this way in quite a few codes and they all worked without any issues.
We don't believe that anymore

Regards, Jan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connecting to DB Error
 
Similar Threads
Connecting To Database
Need help
connecting to ms access database
JdbcOdbc Connection
URL error (DSN not found)