Solved

java.sql exception error: connection refused.

Posted on 1998-11-23
3
543 Views
Last Modified: 2010-08-05
Hi
I'm trying to develop a JDBC application for the 1st time.
I have an oracle server running on another machine and when
I run the following code, I get a "No suitable driver" sql exception error. Does this mean a proper JDBC driver is NOT
installed? what is wrong?
-------
String url = "jdbc:oracle:thin:@skmst1:1525:MODC";
        Connection con;
        String createString;
Statement stmt;

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
        } catch(java.lang.ClassNotFoundException e) {
            System.err.print("ClassNotFoundException: ");
            System.out.println("ClassNotFoundException: ");
            System.err.println(e.getMessage());
        }
try {
            con = DriverManager.getConnection(url,"intcuser", "intcmilp");
} catch(SQLException ex) {
            System.err.println("SQLException: " + ex.getMessage());

}
-----

Thanks

JJ
0
Comment
Question by:jinjool
3 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 1228119
this code
>>  try {
>>            Class.forName("oracle.jdbc.driver.OracleDriver");
>>     } catch(java.lang.ClassNotFoundException e) {

should load the appropriate JDBC driver. since you don't receive exceptions, the driver should have been properly installed ...

this line
>>   String url = "jdbc:oracle:thin:@skmst1:1525:MODC";
is the URL you're going to connect to
and this line
>>   con = DriverManager.getConnection(url,"intcuser", "intcmilp");
ask DriverManager to find suitable driver for this url and give you a connection.
DriverManager looks at the url and choses the appripriate driver, so if you have installed the driver and DriverManager can't find it, most probably this is misspelled URL. so, check the url string (and maybe take a look at oracle documentation / examples)

hope this helps
  heyhey
0
 
LVL 1

Accepted Solution

by:
GregL earned 60 total points
ID: 1228120
The connection refused usually means that the connect string is wrong.  It should be:
jdbc:oracle:thin:@<server name>:port:sid
I made the mistake of using the tnsnames entry instead of the sid and got the same error.

GregL
0
 

Author Comment

by:jinjool
ID: 1228121
NO,..I'm positive I have the right SID name.
I think it's because the driver was not installed properly
since after upgrading (reinstalling) oracle, it now seems to
work. Thanks for your input though - GregL and heyhey.. :)



0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Strange loading of website behaviour 3 32
eclipse java  build path 6 45
JavaScript/Java - Changing an image background color 4 56
Java DateChooser? 3 29
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now