java.sql.SQLException: QueryRunner requires a DataSource to be invoked in this w
package com.tx.dao;
import java.sql.SQLException;
import java.util.List;
import com.tx.vo.Emp;
public interface IEmpDao {
/*查询所有员工*/
List<Emp> selectAll() throws SQLException ;
}
==============================================================================================
package com.tx.dao.impl;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import com.tx.dao.IEmpDao;
import com.tx.util.DruidUtil;
import com.tx.vo.Emp;
public class EmpDaoImpl implements IEmpDao{
@Override
public List<Emp> selectAll() throws SQLException {
return DruidUtil.qr.query("select * from emp", new BeanListHandler<Emp>(Emp.class));
}
}
==============================================================================================
package com.tx.service;
import java.sql.SQLException;
import java.util.List;
import com.tx.vo.Emp;
public interface IEmpService {
List<Emp> selectAll() throws SQLException ;
}
===============================================================================================
package com.tx.service.impl;
import java.sql.SQLException;
import java.util.List;
import com.tx.dao.IEmpDao;
import com.tx.dao.impl.EmpDaoImpl;
import com.tx.service.IEmpService;
import com.tx.vo.Emp;
public class EmpServiceImpl implements IEmpService{
IEmpDao empDao=new EmpDaoImpl();
@Override
public List<Emp> selectAll() throws SQLException {
return empDao.selectAll();
}
}
=============================================================================================
package com.tx.vo;
public class Emp {
private Integer empno;
private String ename;
private String job;
private String deptno;
public Integer getEmpno() {
return empno;
}
public void setEmpno(Integer empno) {
this.empno = empno;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public String getDeptno() {
return deptno;
}
public void setDeptno(String deptno) {
this.deptno = deptno;
}
@Override
public String toString() {
return "Emp [empno=" + empno + ", ename=" + ename + ", job=" + job + ", deptno=" + deptno + "]";
}
}
==============================================================================================
package com.tx.servlet;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.tx.service.IEmpService;
import com.tx.service.impl.EmpServiceImpl;
import com.tx.vo.Emp;
/**
* Servlet implementation class EmpServlet
*/
public class EmpServlet extends HttpServlet {
IEmpService empService=new EmpServiceImpl();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String pathInfo=request.getPathInfo().substring(1);
if("listAll".equals(pathInfo)){
ListAll(request,response);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
private void ListAll(HttpServletRequest request, HttpServletResponse response) {
try {
//调用业务成的方法拿到所有员工
List<Emp> emps=empService.selectAll();
//request对象绑定属性员工list
request.setAttribute("empList",emps);
//转发到jsp处理页面
request.getRequestDispatcher("/student/student_list.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
==============================================================================================
package com.tx.util;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.commons.dbutils.QueryRunner;
public class DruidUtil {
public static DataSource dataSource;
static{
InputStream input=DruidUtil.class.getClassLoader().getResourceAsStream("druid.properties");
Properties prop=new Properties();
try {
prop.load(input);
} catch (IOException e) {
e.printStackTrace();
}
}
public static QueryRunner qr=new QueryRunner(dataSource);
public static Connection getConnection(){
try {
return dataSource.getConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
===============================================================================================
driverClassName = oracle.jdbc.driver.OracleDriver
url = jdbc:oracle:thin:@localhost:1521:orcal
username = scott
password = tiger
initialSize = 5
maxActive = 10
minIdle = 3
maxWait = 10000
=============================================================================
java.sql.SQLException: QueryRunner requires a DataSource to be invoked in this way, or a Connection should be passed in
at org.apache.commons.dbutils.AbstractQueryRunner.prepareConnection(AbstractQueryRunner.java:315)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:345)
at com.tx.dao.impl.EmpDaoImpl.selectAll(EmpDaoImpl.java:17)
at com.tx.service.impl.EmpServiceImpl.selectAll(EmpServiceImpl.java:15)
at com.tx.servlet.EmpServlet.ListAll(EmpServlet.java:46)
at com.tx.servlet.EmpServlet.doGet(EmpServlet.java:31)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
求大神帮忙解决,谢谢~~~~~~~~~~