Home » Developer & Programmer » JDeveloper, Java & XML » I get a SQLException, when trying to connect to oracle (Oracle 9i, Netbeans 5.5 with JDK 1.5)
I get a SQLException, when trying to connect to oracle [message #381652] Mon, 19 January 2009 02:29 Go to next message
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 #381658 is a reply to message #381652] Mon, 19 January 2009 02:45 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
An exception has a name, a number, an associated message.
The purpose of these is to help to know what is the problem.
Wihtout these you can't know what is the problem and your only option is to pray.

Regards
Michel
Re: I get a SQLException, when trying to connect to oracle [message #381662 is a reply to message #381658] Mon, 19 January 2009 02:59 Go to previous messageGo to next message
Mellowd
Messages: 10
Registered: January 2009
Location: South Africa
Junior Member
This is the exception I'm getting, I also need to know if there's something wrong with my code.

Exception:: java.sql.SQLException: Io exception: SO Exception was generated

Re: I get a SQLException, when trying to connect to oracle [message #381667 is a reply to message #381662] Mon, 19 January 2009 03:14 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Why do you think it has anything to do with SQL?

Regards
Michel
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 Go to previous messageGo to next message
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 #381673 is a reply to message #381668] Mon, 19 January 2009 03:29 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Use "e.printStackTrace"

Regards
Michel
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 #381824 is a reply to message #381729] Tue, 20 January 2009 00:49 Go to previous messageGo to next message
Mellowd
Messages: 10
Registered: January 2009
Location: South Africa
Junior Member
Hi Frank

The content of serverName is: "DEV1" which is the name of my Oracle server.
Re: I get a SQLException, when trying to connect to oracle [message #381856 is a reply to message #381824] Tue, 20 January 2009 02:32 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
try <server>:<port>:<SID>

eg: jdbc:oracle:thin:@localhost:1521:XE
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 #381935 is a reply to message #381933] Tue, 20 January 2009 06:18 Go to previous messageGo to next message
Michel Cadot
Messages: 68624
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
ORA-12505: TNS:listener does not currently know of SID given in connect descriptor
 *Cause:  The listener received a request to establish a connection to a
 database or other service. The connect descriptor received by the listener
 specified a SID for an instance (usually a database instance) that either
 has not yet dynamically registered with the listener or has not been
 statically configured for the listener. This may be a temporary condition
 such as after the listener has started, but before the database instance
 has registered with the listener.
 *Action:
  - Wait a moment and try to connect a second time.
  - Check which instances are currently known by the listener by executing:
    lsnrctl services <listener name>
  - Check that the SID parameter in the connect descriptor specifies
    an instance known by the listener.
  - Check for an event in the listener.log file.

Regards
Michel
icon14.gif  Re: I get a SQLException, when trying to connect to oracle [message #381939 is a reply to message #381935] Tue, 20 January 2009 06:34 Go to previous messageGo to next message
Mellowd
Messages: 10
Registered: January 2009
Location: South Africa
Junior Member
U made My day Michel, thanx to u I'm connected!!! Really appreciate your help
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 Go to previous messageGo to next message
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 #382057 is a reply to message #381973] Tue, 20 January 2009 15:32 Go to previous messageGo to next message
Mellowd
Messages: 10
Registered: January 2009
Location: South Africa
Junior Member
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.
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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
Re: I get a SQLException, when trying to connect to oracle [message #382151 is a reply to message #382135] Wed, 21 January 2009 03:06 Go to previous message
Frank
Messages: 7901
Registered: March 2000
Senior Member
If it works with whatever URL you use now, it works Smile

The construction I showed you, is the way jdbc-url's are normally constructed.
The top URL for Oracle related stuff really is Google. You can find most anything through it. Combine your search terms with the term "oracle" and a world of solutions opens up.
All Oracle documentation can be found at http://tahiti.oracle.com

And of course, always feel free to ask questions here at OraFAQ!

[Updated on: Wed, 21 January 2009 03:06]

Report message to a moderator

Previous Topic: Calling an Oracle Form and passing parameters from a jsp
Next Topic: How to write a Java code in oracle
Goto Forum:
  


Current Time: Thu Mar 28 09:42:14 CDT 2024