[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 551
  • Last Modified:

java.sql exception error: connection refused.

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
jinjool
Asked:
jinjool
1 Solution
 
heyhey_Commented:
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
 
GregLCommented:
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
 
jinjoolAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now