JAVA tomcat 6 连mysql 出问题了 org.apache.tomcat.dbcp.dbcp.BasicDataSource
错误:java.lang.ClassCastException:org.apache.tomcat.dbcp.dbcp.BasicDataSourceatorg.webb...
错误:
java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.BasicDataSource
at org.webb.login.LoginServlet.doGet(LoginServlet.java:38)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
配置:apache-tomcat-6.0.18\conf\context.xml
<Context>
<Resource name="jdbc/sotpas"
auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="123456"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306 liuupeng?characterEncoding=utf8"/>
</Context>
我是新手,麻烦得各位高手帮下!谢谢
源程序:package org.webb.login;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sun.jdbc.odbc.ee.DataSource;
public class LoginServlet extends HttpServlet {
public LoginServlet() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Context initContext;
try {
initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/sotpas");
if(ds==null){
System.out.println("获得数据源成功");
} 展开
java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.BasicDataSource
at org.webb.login.LoginServlet.doGet(LoginServlet.java:38)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
配置:apache-tomcat-6.0.18\conf\context.xml
<Context>
<Resource name="jdbc/sotpas"
auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="123456"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306 liuupeng?characterEncoding=utf8"/>
</Context>
我是新手,麻烦得各位高手帮下!谢谢
源程序:package org.webb.login;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sun.jdbc.odbc.ee.DataSource;
public class LoginServlet extends HttpServlet {
public LoginServlet() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Context initContext;
try {
initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/sotpas");
if(ds==null){
System.out.println("获得数据源成功");
} 展开
4个回答
展开全部
url="jdbc:mysql://127.0.0.1:3306 liuupeng?characterEncoding=utf8"/>
应该改成
url="jdbc:mysql://127.0.0.1:3306/liuupeng?characterEncoding=utf8"/>
应该改成
url="jdbc:mysql://127.0.0.1:3306/liuupeng?characterEncoding=utf8"/>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
JNDI (as you configured in context.xml) returns "javax.sql.DataSource" but you wanted to cast it to "sun.jdbc.odbc.ee.DataSource"
another thing is that the connection url seems incorrect -- missing a slash "/" after port
another thing is that the connection url seems incorrect -- missing a slash "/" after port
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我也遇到这个问题了...希望能尽快解决
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
应该是你添加的 数据库驱动的包有问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |