java.lang.ClassNotFoundException in spite of using

2019-01-01 02:49发布

I am trying to connect to mysql database using java on windows7. In spite of adding the complete url of jdbcdriver jar file in CLASSPATH, java.lang.ClassNotFoundException: com.mysql.jdbc.Driver is thrown. Could anyone tell me what i am missing here? It works if I add the jar file in project library but I want to do it by CLASSPATH itself. My classpath looks like this- C:\jython2.5.1\javalib\mysql-connector-java-5.1.12-bin.jar

I want to make it clear that this is not the actual project i am working on. I am actually using Django with Jython, which requires the JDBC driver to access the database. That is the reason why I have to do it using CLASSPATH only.

9条回答
不流泪的眼
2楼-- · 2019-01-01 03:02

What finally helped me out was to copy the mysql-connector-java-5.1.15-bin.jar to \jre\lib and to \jre\lib\ext both(!) even though I did all the classpathing circus Java offers :) Environment was pure notepad/commandline though.

查看更多
孤独寂梦人
3楼-- · 2019-01-01 03:03

If you are using maven, add the dependency to pom.xml should solve the problem.

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.36</version>
</dependency>
查看更多
其实,你不懂
4楼-- · 2019-01-01 03:10

In Netbeans IDE just Check the properties of Project on which you working on,in properties window go to 'library' tag, in diolog box just add your mysql-connector-java-**.jar file.

查看更多
登录 后发表回答