0

I already saw many post where people were trying to add the driver. I'm using intelij as IDE and added the driver under Modules => Dependencies => Add Jar; So my IDE identified the driver and can show me the source file of it. My problem is, as soon i start my server I'll get that error that he couldn't find the driver:

My Code:

private void createDB()
{
    try {
        Class.forName("com.mysql.jdbc.Driver");
        database = DriverManager.getConnection("jdbc:mysql://***:" + 3307 + "/**db", "", "");

    } catch (Exception e) {
        e.printStackTrace();
    }

}

My exception:

> java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader.findClass(Unknown Source)
fxrbfg
  • 1,756
  • 1
  • 11
  • 17
  • are you using maven or gradle or something like this? – Alexander Mar 31 '18 at 11:41
  • 1
    Can you show us your build file (`build.gradle` / `settings.gradle` or `pom.xml`)? – filpa Mar 31 '18 at 11:41
  • @user991710 Thats in my .iml file: – Jochaim Fischbach Mar 31 '18 at 12:22
  • @Alexander Nopeits just based on my Java SDK – Jochaim Fischbach Mar 31 '18 at 12:26
  • 1
    What servlet container are you using? Probably the jdbc driver needs to be set up in the server lib, not in the application classpath. See https://serverfault.com/q/77388/86698 – Nathan Hughes Mar 31 '18 at 12:30
  • @JochaimFischbach `ClassNotFoundException` occurs when your code (or a library that your code uses) could not be found when trying to refer to this class (either with `new` or any other kind of initialization method). As Nathan mentioned, the JDBC `jar` that you are using is most likely not present in your classpath during runtime. After compiling, please verify that the required `jar` is present in your `build` directory. See also [this answer](https://stackoverflow.com/questions/15748874/how-to-add-the-jdbc-mysql-driver-to-an-eclipse-project). – filpa Mar 31 '18 at 13:10
  • @user991710 I switched now to Eclipse again but still got the error. Lib is showed in my class path and also exist is in my project source folder. Its frustrating.... – Jochaim Fischbach Mar 31 '18 at 16:46
  • The jdbc driver is used by the servlet container as it creates a connection pool. Driver implementation classes typically aren't directly used by the application. See the documentation for your servlet container; the jdbc jar needs to be placed where the servlet container can find it. See the link I posted previously. – Nathan Hughes Apr 02 '18 at 02:29

0 Answers0