1

I have seen many solutions in Stack Overflow but none of them worked for me. So I am getting this exception. My pom.xml code is here

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
  <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>

I have added jar file in tomcat/lib folder also. But nothing is working for me.

5
  • 2
    Did you do a maven update? Commented Jun 27, 2017 at 21:56
  • You should rebuild project with the new pom.xml for changes to take effect Commented Jun 27, 2017 at 21:57
  • By the way, please take a time to go through the welcome tour to know your way around here (and also to earn your first badge), read how to create a Minimal, Complete, and Verifiable example and also check How to Ask Good Questions so you increase your chances to get feedback and useful answers. Commented Jun 27, 2017 at 22:00
  • @GrayCygnus, you mean i need to delete current pom.xml and again create new pom.xml? Commented Jun 27, 2017 at 22:03
  • @PraveenRB i mean you should build the project again, check my answer for more details Commented Jun 27, 2017 at 22:12

1 Answer 1

1

You should rebuild your Maven project after adding new dependencies, either directly on Eclipse if you have the m2e built-in support (which you should, as explained and recommended in this question),

By right-clicking on the project name and then doing Maven->Update project (as @BackSlash suggests)

Also, looking at your pom.xml you are not nesting that <dependency> inside the <dependencies> tag, my db connector (postgress) looks something like this:

<dependencies>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.0.0.jre7</version>
    </dependency>

    ... more <dependency> here...
</dependencies>

You can check this great link that explains how to write pom.xml files when creating and building Java projects with Maven.

Edit:

Remember to call the driver exactly like "com.mysql.jdbc.Driver", with capital 'd'.

Sign up to request clarification or add additional context in comments.

11 Comments

Also, without rebuilding the project by hand, eclipse has an option for it. Right-click on the project name->Maven->Update project rebuilds the project and checks all dependencies (and downloads missing jars)
actually i had a nested dependencies tag, but i did not write it in question
Please never ever recommend running mvn eclipse:eclipse. It's been officially retired for almost 2 years and has been breaking m2e eclipse integration for at least 4 years. It was designed to provide some integration between Eclipse and Maven before the advent of m2e and is not compatible with it.
@GrayCygnus, problem got solved i made a silly mistake.while loading drive class insted of writing Class.forname("com.mysql.jdbc.Driver"); i had written driver (d in small letter).
From now i will post qualified questions. Thanks for supporting me.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.