JAVA MySQL连接ClassNotFound异常 [英] JAVA MySQL Connection ClassNotFound Exception

查看:103
本文介绍了JAVA MySQL连接ClassNotFound异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package cs352hw;
import java.sql.Connection;
import java.sql.DriverManager;
public class Main {
   public static void main(String[] args) {
    // TODO code application logic here
      DB db = new DB();
            Connection conn=db.dbConnect(
              "jdbc:mysql://dijkstra.ug.bcc.bilkent.edu.tr",
              "",
              "");
      }

}


      //This Class is taken from http://www.java-tips.org/other-api-tips/jdbc/how-to-connect-mysql-server-using-jdbc.html
class DB
   {
    public DB() {}

    public Connection dbConnect(String db_connect_string,
      String db_userid, String db_password)
    {
            try
            {
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                    Connection conn = DriverManager.getConnection(
                      db_connect_string, db_userid, db_password);

                    System.out.println("connected");
                    return conn;

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

大家好,我的课程在上面

Hey guys my classes are given above

我是jdbc的新手

请帮助我,我遇到这样的运行时错误

Please help me I am getting run time error such that

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

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

谢谢您的建议

注意:我不知道如何将jar文件放入我的类路径并动态绑定它:S

Note: I don't know How to put the jar file into my classpath and bind it dynamically :S

推荐答案

您需要下载

You need to download the MySQL Connector/J and add the .jar file in your application

将jar文件添加到WEB-INF/lib(如果是Web应用程序),否则添加到项目的lib文件夹中,然后尝试运行

Add the jar file in the WEB-INF/lib, if its a web-app, else in the lib folder of your project and then try to run

这篇关于JAVA MySQL连接ClassNotFound异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆