Solved

java.sql exception error: connection refused.

Posted on 1998-11-23
3
542 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 2 42
Fibonacci challenge 11 82
network + 7 73
topping1 challenge 7 50
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 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

15 Experts available now in Live!

Get 1:1 Help Now