我的动态Web项目中的MySQL驱动程序问题(JPA,JSP)

时间:2011-04-29 07:33:10

标签: mysql eclipse jsp jpa jdbc

切入案件。

的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">

        <persistence-unit name="fishsticks" transaction-type="RESOURCE_LOCAL">
            <class>model.Customer</class>
            <etc etc>

            <properties>
                <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
                <property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/fishsticks" />
                <property name="javax.persistence.jdbc.user" value="user" />
                <property name="javax.persistence.jdbc.password" value="pass" />

                <!-- EclipseLink should create the database schema automatically -->
                <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
                <property name="eclipselink.ddl-generation.output-mode"
                    value="database" />
                <property name="eclipselink.logging.level" value="OFF" />
            </properties>
        </persistence-unit>
</persistence>

Eclipse构建路径:

enter image description here

项目设置:

enter image description here

我页面上的错误: enter link description here

该页面由jsp

制作

我不知道如何解决这个问题......

这是我的DAO文件:

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import model.Customer;
import model.Milestone;
import model.Project;
import model.Task;
import model.User;

public class JpaDAO implements DAO {
    private static JpaDAO dao;

    public static JpaDAO getInstance() {
        if (dao == null)
            dao = new JpaDAO();
        return dao;
    }

    private EntityManagerFactory emf = Persistence.createEntityManagerFactory("fishsticks");

    @PersistenceContext(name="fishsticksEM")
    private EntityManager em = emf.createEntityManager();
    private EntityTransaction tx = em.getTransaction();

    private JpaDAO() {
        // singleton
    }
}

1 个答案:

答案 0 :(得分:3)

您是否遵循了tomcat documentation的建议?

  

在继续之前,不要忘记   将JDBC驱动程序的jar复制到   $ CATALINA_HOME / lib中

这适用于Tomcat 6.0和7.0。

对于Tomcat 5.5:$CATALINA_HOME/common/lib