aspose file tools*
The moose likes JDBC and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exception in thread "main" java.sql.SQLException: No suitable driver" Watch "Exception in thread "main" java.sql.SQLException: No suitable driver" New topic
Author

Exception in thread "main" java.sql.SQLException: No suitable driver

Rosy Mary
Greenhorn

Joined: Jan 08, 2009
Posts: 16
Hi,

I am new to Java concepts. When i am trying to establish JDBC conncetion with Oraqcle 9i i am getting the below error:

Can any one of you sugust me solution for this:

Exception in thread "main" java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at JDBC1.main(JDBC1.java:13)

This is the syntax i am using to connect. Please help me out::

Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:odbc:thin:@localhost:1521","scott","tiger");

Thanks in Advance.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10520
    
    9

Hi Poornima,
Welcome to the ranch. We are happy to have you here

As you have seen, we have quite a lot of forums. If you post on the proper forum you can get the most out of the ranch.
Moving this to an appropriate forum.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10520
    
    9

Is the required .jar file in your classpath?
Rosy Mary
Greenhorn

Joined: Jan 08, 2009
Posts: 16
Thanks for your reply. I have the following located in my class path:

C:\oracle\ora92\jdbc\lib\classes12.zip;

Please let me know what needs to be done.

Thanks in Advance.
Rosy Mary
Greenhorn

Joined: Jan 08, 2009
Posts: 16
What should be the .Jar file used to be placed in the class path?

Thanks.
Sujai Kaarthik
Ranch Hand

Joined: Dec 29, 2008
Posts: 162
con=DriverManager.getConnection("jdbc:odbc:thin:@localhost:1521:xxxx","scott","tiger");

I think you have missed the database name. Replace the database name with xxxx


[edit]Disable smilies. CR[/edit]


The greater danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it
Rosy Mary
Greenhorn

Joined: Jan 08, 2009
Posts: 16
Ya i have tried that option too but no use still the error persists.. Any other cause for this error??

Thanks.
Sujai Kaarthik
Ranch Hand

Joined: Dec 29, 2008
Posts: 162
have you imported the corresponding package?
Because, I have did that fault many times
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3855

Poornima Yeleswarapu wrote:Thanks for your reply. I have the following located in my class path:

C:\oracle\ora92\jdbc\lib\classes12.zip;

Please let me know what needs to be done.


classes12.jar is for JDK 1.2 and 1.3 according to the oracle. Which JDK version you are using? You have to download the appropriate driver from there and place it in the classpath, then try it.
Sujai Kaarthik
Ranch Hand

Joined: Dec 29, 2008
Posts: 162
If you are using Oracle, try thiS:

Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521:yyyy","scott","tiger");
Rosy Mary
Greenhorn

Joined: Jan 08, 2009
Posts: 16
The java veriosn i am using is "1.5.0_06". And i have imported the required package import java.sql.*;
I thing i am using the correct syntax to get the veriosn?
I have used java -version to get this. Correct me if i am wrong......
Sujai Kaarthik
Ranch Hand

Joined: Dec 29, 2008
Posts: 162
Exception in thread "main" java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at JDBC1.main(JDBC1.java:13)


I think this error will popup only when there is an error in the parameters you pass in the getConnection(...)
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3855

Poornima Yeleswarapu wrote:
I thing i am using the correct syntax to get the veriosn?
I have used java -version to get this. Correct me if i am wrong......


Yes, That's right.
Have you go through the link I gave above. I haven't tried this but you better use the appropriate driver implementation to suit your JDK version and check the documentation for the correct class name and the URL

Rosy Mary
Greenhorn

Joined: Jan 08, 2009
Posts: 16
Might be but i am not sure if there is any mistake in the syntax of that... Anyways need to try again...

Thanks in Advacne.
Sujai Kaarthik
Ranch Hand

Joined: Dec 29, 2008
Posts: 162
just try replacing "odbc" with "oracle" and see whether it works or not.
I also use Oracle as my backend and I use to specify like this:

con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521:yyyy","scott","tiger");

and not

con=DriverManager.getConnection("jdbcdbc:thin:@localhost:1521:yyyy","scott","tiger");
Sujai Kaarthik
Ranch Hand

Joined: Dec 29, 2008
Posts: 162
Poornima Yeleswarapu wrote:Might be but i am not sure if there is any mistake in the syntax of that... Anyways need to try again...

Thanks in Advacne.


there is no syntax error, but there might be wrong parameters

though I am not sure about it
Rosy Mary
Greenhorn

Joined: Jan 08, 2009
Posts: 16
Ya tried using the above syntax and i now encounter this error: do not know what this means.....
since i am using Oracle......


con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521:yyyy","scott","tiger");

java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNU
M=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:333)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:404)

at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
va:468)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at OraThin.main(OraThin.java:9)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39803
    
  28
Sounds like something which would sit better on our JDBC forum . . . moving
Sujai Kaarthik
Ranch Hand

Joined: Dec 29, 2008
Posts: 162
con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521:yyyy","scott","tiger");


its not jdbcracle. the smiley took the colon-":" and "o"!!

its "jdbc: oracle:thin:@localhost:1521:yyyy" , where YYYY is your database name.

remove the space between : and oracle

I just altered my code in an application as your's code. It shows the same error. The above solution should solve your problem
George Hutto
Greenhorn

Joined: Mar 12, 2003
Posts: 8
Okay, I'm having much the same problem. I'm new to using JDBC so I've tried going through the same steps to resolve the issue but with no luck. Please help.

I'm using Eclipse and JDeveloper (having same problem in both environments) in Windows 7.

This is the entirety of my environment variable "CLASSPATH = c:\oracle\sqldeveloper\jdbc\ojdbc6.jar". Should there be more?

My code is as follows:

import java.sql.*;

public class ptSQL {

public static void main(String args[]) throws ClassNotFoundException, SQLException{
Class.forName("oracle.jdbc.driver.OracleDriver");

Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=devel-ora-db1.bdainc.bda)(PORT=1521))" +
"(PROTOCOL=tcp)(CONNECT_DATA=(SERVICE_NAME=EBSDEVL)(INSTANCE_NAME=EBSDEVL)))",
someuserid,
somepassword);
conn.close();
}

}

Very basic, I just want to see if I can open the connection. Once I get to that point the rest will be easy.

thanks in advance.

Joshi Nirav
Greenhorn

Joined: Dec 04, 2009
Posts: 14

Hi George,

Can you try the simple one connection String like ,



Please don't forget to replace the xxxx=Your Schema name.

Make sure that your TNSListener service Of Oracle Database Server is running.

Thanks and Regards
Nirav Joshi

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

When you say you have "the same problem", that's a bit confusing because there were at least two different problems discussed in the thread you grabbed onto. Could you spare a minute and provide a description of your problem?
sai vangari
Greenhorn

Joined: Apr 14, 2012
Posts: 5
guys, i have no issues with the drivers..but having some problems related to the url connection...i would like to know what after the port number should be specified..and also which username and password should i use:as i use different (username and password) at sql command prompt and system as username and **** as password at the oracle homepage..
thanks in advance!!
Padmalochan pathi
Greenhorn

Joined: Aug 10, 2013
Posts: 1
Hi
I have tried to run this program..but failed due to the exception i.e. java.sql.SQLException: could not resolve the connect identifier specified

can you please help me regarding this problem .


import java.sql.*;

class Ex_Type1_Oracle_Update
{
public static void main(String args[])throws Exception
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbcracleci:@XE","adv11am","adv11am");
Statement st=con.createStatement();
int count= st.executeUpdate("Update doctor2 set dsal=dsal+200 where did=1");
System.out.println(count+"record/s updated successfully");
con.commit();
st.close();
con.close();
}}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.sql.SQLException: No suitable driver