This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes java.sql.SQLException: No suitable driver found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: No suitable driver found" Watch "java.sql.SQLException: No suitable driver found" New topic
Author

java.sql.SQLException: No suitable driver found

Anand Sivathanu
Ranch Hand

Joined: Jun 25, 2010
Posts: 76
Hi Friends,

I am new to sql. I am using SQL server 5.5 db.

I would like to establish JDBC connection for a helloworld web application.

I have downloaded jar(mysql-connector-java-5.1.22-bin.jar) for jdbc connection.

When I excecute the code,exception is thrown "java.sql.SQLException: No suitable driver found"

java.sql.SQLException: No suitable driver found for jdbc://localhost:3306/shop
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.user.auth.HelloWorldServlet.doGet(HelloWorldServlet.java:23)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:403)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:301)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:162)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:140)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Please suggest me a valid solution.

Regards,
Anand
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

can you post us the connection code as well please.
It looks like your connection URL may be a problem, but that is just a guess.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Anand Sivathanu wrote:I am new to sql. I am using SQL server 5.5 db.


This is Microsoft's SQL Server? Or did you just use "SQL server" as a general description and you're actually using some other database? (If so, which one?)

I have downloaded jar(mysql-connector-java-5.1.22-bin.jar) for jdbc connection.


That suggests you're using MySQL as your database. That JDBC driver will only work with MySQL, so if you are using some other database, you should start by getting the JDBC driver which goes with it.
Anand Sivathanu
Ranch Hand

Joined: Jun 25, 2010
Posts: 76


This is the connection code....

Class.forName("com.mysql.jdbc.Driver");


Connection con = DriverManager.getConnection("jdbc://localhost:3306/shop","root","root");


Database is MySQL server 5.0. previously i tried in MySQL Server 5.5

Getting same error for both the versions
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

In what folder did you placed the "mysql-connector-java-5.1.22-bin.jar" ?


Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

just done a quick search for mysql connection urls and all the examples followed this pattern:


they include jdbc:mysql

infact this looks goos oracle docs
Anand Sivathanu
Ranch Hand

Joined: Jun 25, 2010
Posts: 76
Wendy Gibbons,

As you said,
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop","root","root");(right)

will work..I will try this in my machine and let you know



Connection con = DriverManager.getConnection("jdbc://localhost:3306/shop","root","root"); (wrong)

Sumit Patil,

"mysql-connector-java-5.1.22-bin.jar" placed in WEB-INF\lib.
Anand Sivathanu
Ranch Hand

Joined: Jun 25, 2010
Posts: 76
Hi friends,

Now I can able to access the table.

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop","root","root");(right code)

Previously it was

Connection con = DriverManager.getConnection("jdbc://localhost:3306/shop","root","root");(wrong code).missing "mysql" near jdbc caused the problem(As Wendy Gibbons said)

Regards,
Anand

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.SQLException: No suitable driver found
 
Similar Threads
axis2 xmlbeans problem
Cannot open connection issue
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing.
Tomcat and jdbc/odbc
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@127.0.0.1:1521:XE