JDBC Report java.lang.ClassNotFoundException:com.mysql.jdbc.Drive

Source: Internet
Author: User

Today, I wrote a jdbc-connected MySQL-driven program from the beginning.

It's really a variety of errors.

First, this is the code.

Package Com.dmeck;import Java.sql.connection;import Java.sql.drivermanager;import java.sql.resultset;import Java.sql.sqlexception;import Java.sql.statement;public class Jdbcbase {public static void main (string[] args) {String url = "Jdbc:mysql://localhost:3306/mytest"; String user= "root"; String pass= "MySQL"; String classname= "Com.mysql.jdbc.Driver"; Try{class.forname (ClassName);} catch (Exception e) {            System.out.print ("Error loading Mysql driver!");            E.printstacktrace ();} Connection connection;try {Connection = drivermanager.getconnection (URL, user, pass); Statement createstatement = Connection.createstatement (); ResultSet query = Createstatement.executequery ("SELECT * from User"), while (Query.next ()) {System.out.println ( Query.getstring ("user")); Connection.close ();} catch (SQLException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}}

Well, let's start with the question.

When the project runs, it appears

Error Loading Mysql driver!Java.lang.ClassNotFoundException:com.mysql.jdbc.Driver at Java.net.URLClassLoader.findClass ( URLClassLoader.java:58w) at Java.lang.ClassLoader.loadClass (Classloader.java:424) at Sun.misc.launcher$appclassloader.loadclass (Launcher.java:331) at Java.lang.ClassLoader.loadClass (Classloader.java:357At JAVA.LANG.CLASS.FORNAME0 (Native Method) at Java.lang.Class.forName (Class.java:264) at Com.dmeck.Jdbcbase.main (Jdbcbase.java:17) Java.sql.SQLException:No suitable driver found forJdbc:mysql://localhost:3306/mytestAt Java.sql.DriverManager.getConnection (drivermanager.java:689) at Java.sql.DriverManager.getConnection (Drivermanager.java:247) at Com.dmeck.Jdbcbase.main (Jdbcbase.java:25)

First of all, I can't reproduce this error because my project is maven managed

The JDBC driver is 5.1.6

This error is caused by a bad maven network, the jar package is wrong, as long as the ECLISPE load jar of byte file is not the following phenomenon indicates that your jar package has a problem

  

JDBC Report java.lang.ClassNotFoundException:com.mysql.jdbc.Drive

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.