做连接时出现下面的一个错误,我确实是建了bookdb这个库了,不知道怎么回事 请指教,谢谢Cannot create PoolableConnectionFactory (Server connection failure during transaction. Due to underlying exception: 'java.sql.SQLException: Incorrect database name 'jdbc/bookdb''. ** BEGIN NESTED EXCEPTION ** java.sql.SQLException MESSAGE: Incorrect database name 'jdbc/bookdb' STACKTRACE: java.sql.SQLException: Incorrect database name 'jdbc/bookdb' at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:771) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3662) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1176) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2669) at com.mysql.jdbc.Connection.(Connection.java:1474) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266) at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37) at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540) at org.apache.jsp._1_jsp._jspService(org.apache.jsp._1_jsp:58) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Unknown Source) ** END NESTED EXCEPTION ** Attempted reconnect 3 times. Giving up.) 我的server.xml
 <Context path="/bookstore" docBase="bookstore"
          debug="5" reloadable="true" crossContext="true">
          <Resource name="jdbc/book" auth="Container" type="javax.sql.DataSource"
          
               maxActive="100" maxIdle="30" maxWait="10000"
               username="dbuser" password="1234" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://127.0.0.1:3306/jdbc/bookdb?autoReconnect=true"/>
  </Context>      
web.xml<web-app> <resource-ref>
       <description>DB Connection</description>
       <res-ref-name>jdbc/book</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
   </resource-ref>
  
</web-app>
源文件
<%@page contentType="text/html; charset=GBK"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.naming.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test of connection pool</title>
</head>
<body>
<%
out.print("Start<br/>");
try{
 InitialContext ctx = new InitialContext();
 javax.sql.DataSource connectionPool = (javax.sql.DataSource) ctx.lookup("java:comp/env/jdbc/book");
 Connection conn = connectionPool.getConnection();
 out.print("DB connection pool run OK!");
 conn.close();
}
catch(Exception ex){
 out.print(ex.getMessage());
 ex.printStackTrace();
}
%>
</body>
</html>
新手请多多指教

解决方案 »

  1.   

    javax.sql.DataSource connectionPool = (javax.sql.DataSource) ctx.lookup("java:comp/env/jdbc/book");
    应该为:
     javax.sql.DataSource connectionPool = (javax.sql.DataSource) ctx.lookup("java:comp/env/jdbc/bookdb");吧
      

  2.   

    <Context path="/bookstore" docBase="bookstore"
              debug="5" reloadable="true" crossContext="true">
              <Resource name="jdbc/book" auth="Container" type="javax.sql.DataSource"
              
                   maxActive="100" maxIdle="30" maxWait="10000"
                   username="dbuser" password="1234" driverClassName="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://127.0.0.1:3306/jdbc/bookdb?autoReconnect=true"/>
      </Context>
    这里的url好象不对,应该是:
    url="jdbc:mysql://127.0.0.1:3306/bookdb?autoReconnect=true"
      

  3.   

    <web-app> <resource-ref>
           <description>DB Connection</description>
           <res-ref-name>jdbc/bookdb</res-ref-name>
           <res-type>javax.sql.DataSource</res-type>
           <res-auth>Container</res-auth>
       </resource-ref>
      
    </web-app>改什么了~?