runtime error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

前端 未结 6 1173
刺人心
刺人心 2020-11-28 16:13

I am new to mysql and jdbc and I am getting the error in this title. I have been searching all day and cannot find a solution that works for me.

What I have tried:

相关标签:
6条回答
  • 2020-11-28 16:30

    I was also get same problem :-
    How I solved for Linux system.

    1.) Download file mysql-connector-java-5.1.18-bin.jar from given link or other.

    2.) Then paste it to same folder or directory of your class or file (on where you want connection to present)

    3.) Now use the following command by your linux command prompt.

    java -cp .:mysql-connector-java-5.1.18-bin.jar YourFileName ..

    Thats all you need to do... :)

    0 讨论(0)
  • 2020-11-28 16:33

    You need to add a connector library to the Runtime classpath:

    java -cp .;mysql-connector-java-5.1.25-bin.jar ClientBase
    

    My example uses Windows classpath separator ";", on other systems it may be different (":" on Linux/Mac). It also assumes, that mysql-connector-java-5.1.25-bin.jar is located on the same folder. If it's not the case, then put a path to the library instead of the plain name.

    ClientBase stands for Java class file name here

    c:\>javac Test.java
    c:\>java -cp .;F:\CK\JavaTest\JDBCTutorial\mysql-connector-java-5.1.18-bin Test
    
    0 讨论(0)
  • 2020-11-28 16:43

    if u use netbeans,do following 1.Open Netbeans IDE 2.Right-click your Project. 3.Select Properties. 4.On the left-hand side click Libraries. 5.Under "Compile" tab - click Add Jar/Folder button. 6.Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/J from dev.mysql.com) 7.Click OK Run Again... Its work.

    0 讨论(0)
  • 2020-11-28 16:44

    Add mysql.connector-java-x.x.x-bin.jar to your libraries folder. No need to import anything. Have a good one.

    0 讨论(0)
  • 2020-11-28 16:53

    If You Are Using Swing you have to add External Jar of my-sql-connect

    else if You are Using jsp servlet You have to add External jar and Copy that Jar into WEB_INF/lib project folder

    0 讨论(0)
  • 2020-11-28 16:56

    What did you import ? From the documentation: http://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-connect-drivermanager.html

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    // Notice, do not import com.mysql.jdbc.*
    // or you will have problems!
    

    Comment:

    Why are you using notepad++ ? install an IDE (Eclipse/Netbeans/IntelliJ) - it'll be much easier to locate such problems (un-included jars for example)

    0 讨论(0)
提交回复
热议问题