java.lang.AbstractMethodError:org.apache.commons.dbcp.PoolingDataSource $ PoolGuardConnectionWrapper.getSchema()Ljava / lang / String;

时间:2016-01-26 21:08:49

标签: tomcat7 struts-1

我使用Struts1。我尝试以下列方式连接到DataBase:

context.xml(tomcat conf.file):

<Context>
  <Resource name="jdbc/TestDB" auth="Container" type="java.sql.DataSource"
      maxActive="100" maxIdle="30" maxWait="10000"
      username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost:3306/mydb"/>
</Context>

的web.xml

<resource-ref>
  <description>DB Connection</description>
  <res-ref-name>jdbc/TestDB</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

HelloWorldAction.java

import java.sql.Connection;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class HelloWorldAction extends Action{
private DataSource ds;
public ActionForward execute(ActionMapping mapping,ActionForm form,
        HttpServletRequest request,HttpServletResponse response)
        throws Exception {

        HelloWorldForm helloWorldForm = (HelloWorldForm) form;
        helloWorldForm.setMessage("Hello World! Struts");


        try {
            Context ctx = new InitialContext();
            ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");
          } catch (NamingException e) {
            e.printStackTrace();
          }
        Connection con = ds.getConnection();
        System.out.println(con.getSchema());

        return mapping.findForward("success");
    }

}

当我调用这个Action类时,它给了我: java.lang.AbstractMethodError 我使用tomcat7和java 7

0 个答案:

没有答案