Solved

java.sql exception error: connection refused.

Posted on 1998-11-23
3
546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet filter example 37 83
runtime exception 2 50
web project error add remove 1 49
What browser will run Java? 7 122
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 …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

740 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