我的动态web项目(JPA、JSP)中的MySQL驱动程序问题
切题 Persistence.xml我的动态web项目(JPA、JSP)中的MySQL驱动程序问题,mysql,eclipse,jsp,jpa,jdbc,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 ht
<?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>
你是否听从了政府的建议 在你继续之前,别忘了 将JDBC驱动程序的jar复制到 $CATALINA_HOME/lib 这是针对Tomcat6.0和7.0的
对于Tomcat 5.5:
$CATALINA_HOME/common/lib
您是否遵循了
在你继续之前,别忘了
将JDBC驱动程序的jar复制到
$CATALINA_HOME/lib
这是针对Tomcat6.0和7.0的
对于Tomcat 5.5:
$CATALINA_HOME/common/lib
这很有效!在persistence.xml
文件中添加注释
,效果不错!在persistence.xml
文件中包含注释
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
}
}