I get a SQLException, when trying to connect to oracle [message #381652] |
Mon, 19 January 2009 02:29 |
Mellowd
Messages: 10 Registered: January 2009 Location: South Africa
|
Junior Member |
|
|
I imported the ojdbc14.jar into the library and tried to connect to the Oracle server, but for some reason I catch the SQLException, please help. I once connected to this oracle server and it worked fine, but now I catch this SQLException. Here's my code below:
Connection conn;
String serverName = "localhost";
String username = "Scott";
String password = "Tiger";
String connectionURL = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
connectionURL = "jdbc:oracle:thin:@" + serverName;
conn=DriverManager.getConnection(connectionURL,username,password);
System.out.println( "Connected......." );
}
catch (SQLException y)
{
System.err.println( "Failed to load JDBC/ODBC driver." );
}
catch (ClassNotFoundException g)
{
System.err.println( "The class was not found" );
}
|
|
|
|
|
|
Re: I get a SQLException, when trying to connect to oracle [message #381668 is a reply to message #381667] |
Mon, 19 January 2009 03:17 |
Mellowd
Messages: 10 Registered: January 2009 Location: South Africa
|
Junior Member |
|
|
I changed the message where I catch the SQLException to display the name of the exception and it shows that its a SQL exception. I changed the code to:
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
connectionURL = "jdbc:oracle:thin:@" + serverName;
conn=DriverManager.getConnection(connectionURL,username,password);
System.out.println( "Connected......." );
}
catch (SQLException y)
{
System.err.println(y );
}
|
|
|
|
Re: I get a SQLException, when trying to connect to oracle [message #381689 is a reply to message #381673] |
Mon, 19 January 2009 04:42 |
Mellowd
Messages: 10 Registered: January 2009 Location: South Africa
|
Junior Member |
|
|
I used the printStackTrace and this is what I got:
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3668)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:353)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:371)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:551)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:351)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at clobinserter.Main.main(Main.java:84)
|
|
|
Re: I get a SQLException, when trying to connect to oracle [message #381729 is a reply to message #381668] |
Mon, 19 January 2009 08:32 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
Mellowd wrote on Mon, 19 January 2009 10:17 | I changed the message where I catch the SQLException to display the name of the exception and it shows that its a SQL exception. I changed the code to:
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
connectionURL = "jdbc:oracle:thin:@" + serverName;
conn=DriverManager.getConnection(connectionURL,username,password);
System.out.println( "Connected......." );
}
catch (SQLException y)
{
System.err.println(y );
}
|
What's the content of serverName?
[Edit: Sorry, just now I see it in the first post]
The URL should also contain a portnumber and SID
[Updated on: Mon, 19 January 2009 08:33] Report message to a moderator
|
|
|
|
|
Re: I get a SQLException, when trying to connect to oracle [message #381862 is a reply to message #381856] |
Tue, 20 January 2009 02:40 |
Mellowd
Messages: 10 Registered: January 2009 Location: South Africa
|
Junior Member |
|
|
Class.forName("oracle.jdbc.driver.OracleDriver");
connectionURL = "jdbc:oracle:thin:@" + serverName + ":1521:ORCL";
conn=DriverManager.getConnection(connectionURL,username,password);
System.out.println( "Connected......." );
Already tried I now get this error:
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3668)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:353)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:371)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:551)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:351)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at clobinserter.Main.main(Main.java:84)
|
|
|
Re: I get a SQLException, when trying to connect to oracle [message #381933 is a reply to message #381862] |
Tue, 20 January 2009 06:09 |
Mellowd
Messages: 10 Registered: January 2009 Location: South Africa
|
Junior Member |
|
|
I connected remotely to the server and tried working from the server but I now get this error please help:
java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3668)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:353)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:371)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:551)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:351)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at clobber.Main.main(Main.java:85)
|
|
|
|
|
Re: I get a SQLException, when trying to connect to oracle [message #381973 is a reply to message #381939] |
Tue, 20 January 2009 08:54 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
Hm...
Sounds kinda sad to me. You got an error and did not search for it. The only thing Michel did was copy-paste the description of the error from the Oracle documentation.
Not to belittle Michel's response, but if that's a lifesaver to you, you might review your development skills..
[Edit: Reread my reply; it's looking harsher than I mean it; Did not mean to offend, I just was surprised by your cheerful response to quite a standard reply]
[Updated on: Tue, 20 January 2009 08:55] Report message to a moderator
|
|
|
|
Re: I get a SQLException, when trying to connect to oracle [message #382111 is a reply to message #382057] |
Wed, 21 January 2009 00:28 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
Mellowd wrote on Tue, 20 January 2009 22:32 | But Frank u tried to help, and u failed. If you are so good why didn't u give me the information Michel gave. As for my Dev skill yes I have a lot to learn I only started development last week.
|
Do you mean you still use jdbc:oracle:thin:@DEV1 as URL? (I ask this out of curiosity, because I never seen a jdbc-url used like this)
I don't consider giving people a tip, which leads to other faults because of their misconfigured environments failing. Besides, I don't mind "failing", since it teaches me.
But like I said, I did not want to offend you; apparently my post was indeed too harsh, since it seems you felt offended anyway. Sorry for that then.
[Updated on: Wed, 21 January 2009 00:29] Report message to a moderator
|
|
|
Re: I get a SQLException, when trying to connect to oracle [message #382135 is a reply to message #382111] |
Wed, 21 January 2009 01:43 |
Mellowd
Messages: 10 Registered: January 2009 Location: South Africa
|
Junior Member |
|
|
I'm sorry too Frank.
The truth is I need senior developer's like yourself to tell me what the better way of doing things. As I said: I only started development recently, I used to do support and a bit of DBA. Please tell me what's the best way to construct my URL? Just give me what u think its best and if possible please give me some web sources where I can learn stuff.
Thanx
|
|
|
|