简体   繁体   English

找不到MYSQL驱动程序类

[英]MYSQL driver class not found

Please i'm trying to have a DB data from a jsp file, but the driver class is not found (output error), it works good when i'm executing the java class directly but it's not found when i'm calling it from the jsp file. 请问我正在尝试从jsp文件中获取数据库数据,但是找不到驱动程序类(输出错误),当我直接执行java类时它运行良好但是当我从中调用它时它找不到jsp文件。

Here is the jsp code 这是jsp代码

<%@page import="java.util.*"%>
<%@page import="java.lang.Class"%>
<%@ page language="java" import="DAO.*"%>

<%
 try{
   List<String> names=DB.getNames();
   out.print(names);
   out.flush();
    }
 catch(Exception e)
    {
   e.printStackTrace();
    }
   %>

And basically the same in the java class when executing the main . 并且在执行main时java类中基本相同。

public static void main(String[] args){
for(Iterator it=DB.getNames().iterator(); it.hasNext();) 
    System.out.println(it.next()); 

 }

Works good from java directly but not found when called from jsp. 从java直接工作,但从jsp调用时找不到。

The error shows the problem in the db connection function an especialy in this line com.mysql.jdbc.Driver 该错误显示数据库连接函数中的问题,特别是在此行com.mysql.jdbc.Driver

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at DAO.DB.connect(DB.java:21)
at DAO.DB.getNames(DB.java:35)

This issue is being faced because, your Tomcat is unable to find this class that is being referenced in your JSP / Java code. 这个问题正在面临,因为您的Tomcat无法找到JSP / Java代码中引用的此类。

You need to place your MySQL Connector/J jar in your CATALINA_HOME/lib folder or in <yourApplicationWAR>/WEB-INF/lib , hoping that your DB related code is in the JSP itself. 您需要将MySQL Connector/J jar放在CATALINA_HOME/lib文件夹或<yourApplicationWAR>/WEB-INF/lib ,希望您的DB相关代码在JSP本身中。 Latter is preferred over placing your Connector/J in your Tomcat (or any such similar app-server) Latter比在您的Tomcat(或任何类似的应用程序服务器)中放置Connector / J更受欢迎

If the code is in your JAVA class, then you would need to put it in your IDE classpath & preferably into your CLASSPATH environment variable. 如果代码在您的JAVA类中,那么您需要将它放在IDE类路径中,最好放在CLASSPATH环境变量中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM