2
      conn = DriverManager.getConnection(
        "jdbc:mysql://localhost:3306/ebookshop", "root", "");

XAMPP is hosting MySQL on 3306 I linked the mysql connect jar ebookshop is the name of a DB

https://i.stack.imgur.com/RAQBD.png

I have a user root wit no password

But I am getting a

    java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/ebookshop

    ...

I have run other JSP and it works, I have a print statement just before the conn statement and it prints, one after that does not.

Thank you

2 Answers2

2

You need to add the MySQL JDBC driver to your app's classpath. The most straight forward way to do that if you're running in a servlet container such as Tomcat or Jetty, would be to place the driver jar file in your app's WEB-INF/lib folder.

Asaph
  • 159,146
  • 25
  • 197
  • 199
  • @amiranthist: The driver may very well be in the `WEB-INF/lib` folder in your *project*, but it's likely not getting *deployed* along with your jsp files to your servlet container. If you're using your IDE to deploy, check that the libraries are part of the build package. – Asaph May 14 '13 at 06:44
  • @amiranthist: Are you deploying with Eclipse? If so, go to Project > Properties and then Deployment Assembly. If the MySQL driver from `WEB-INF/lib` is not listed, add it. – Asaph May 14 '13 at 06:47
  • That has not fixed the issue :/ –  May 14 '13 at 06:49
0

Try this code :-

  try
    {
           Class.forName("com.mysql.jdbc.Driver").newInstance();
    }
    catch (Exception e)
    {
        System.out.println("Error in Data base Driver:"+e);
    }
    try 
    {                   
        String url="jdbc:mysql://localhost:3306/ebookshop", "root", ""; 
        connection=DriverManager.getConnection(url,userName,pass);

    }
    catch (Exception e) 
    {           

        System.out.println("Error in database connection:"+e);


    }

First register your driver. Then you can use the url.

JDGuide
  • 6,239
  • 12
  • 46
  • 64