Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.SQLException: No suitable driver found

 
Anand Sivathanu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In what folder did you placed the "mysql-connector-java-5.1.22-bin.jar" ?
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic