http://hackvip.cn/user1/172/archives/2005/6071.html

解决方案 »

  1.   

    by the way, I used the other old way to get connection, it works. But I prefer to use
    datasource than this!
    private static String driverName="com.mysql.jdbc.Driver";

    private static String userName="root"; private static String userPasswd="root"; private static String dbName="bookstore"; private static String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
    Connection conn = null;
    try {
    Class.forName(driverName);
    } catch (java.lang.ClassNotFoundException e) {
    System.err.println("Unable to load driver.");
    System.err.println(e.getMessage());
    } try {
    conn = DriverManager.getConnection(url);
    }
      

  2.   


    this is what I studid , but it did not work.http://www.yesky.com/398/1946398.shtml
      

  3.   


    I also try to create a new properties to look for this datasource. It did not work either.env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
    env.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
    env.put(Context.PROVIDER_URL, "localhost:1099"); /*
    env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_PRINCIPAL, principal);
    env.put(Context.SECURITY_CREDENTIALS, credentials);
    */



    try {
    //ctx = new InitialContext(env);
    ]
      

  4.   

    Context ctx = new InitialContext();
    javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:/BookStore");
    Connection conn=ds.getConnection();
    我也用的jb4和mysql,测试通过。
      

  5.   

    does not work. Error: actually , I have tried this before.
    00:09:12,363 WARN  [JBossManagedConnectionPool] Throwable while attempting to ge
    t a new connection: null
    org.jboss.resource.JBossResourceException: Could not create connection; - nested
     throwable: (org.jboss.resource.JBossResourceException: Apparently wrong driver
    class specified for URL: class: com.mysql.jdbc.Driver, url: jdbc:mysql://localho
    st/bookstore)
            at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.c
    reateManagedConnection(LocalManagedConnectionFactory.java:161)
            at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.cr
    eateConnectionEventListener(InternalManagedConnectionPool.java:508)
            at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.ge
    tConnection(InternalManagedConnectionPool.java:207)
            at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BaseP
    ool.getConnection(JBossManagedConnectionPool.java:534)
            at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManage
    dConnection(BaseConnectionManager2.java:395)
            at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedCo
    nnection(TxConnectionManager.java:297)
            at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateC
    onnection(BaseConnectionManager2.java:447)
            at org.jboss.resource.connectionmanager.BaseConnectionManager2$Connectio
    nManagerProxy.allocateConnection(BaseConnectionManager2.java:874)
            at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrapp
    erDataSource.java:103)
            at com.aip.enterprise.common.DBUtils.getConnection(DBUtils.java:49)
            at com.aip.enterprise.dao.support_mysql.ProductDaoImpl.getAllProductsbyC
    ategory(ProductDaoImpl.java:200)
            at com.aip.enterprise.struts.action.ListproductAction.execute(Listproduc
    tAction.java:81)
            at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
    tProcessor.java:484)
            at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
    va:274)
            at org.apache.struts.action.ActionServlet.process(ActionServlet.java:148
    2)
            at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:252)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:173)
            at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
    lter.java:81)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:202)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:173)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
    alve.java:213)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
    alve.java:178)
            at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrinc
    ipalValve.java:39)
            at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
    yAssociationValve.java:153)
            at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
    torBase.java:407)
            at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
    e.java:59)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
    ava:126)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
    ava:105)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
    ve.java:107)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
    a:148)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
    :856)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
    ssConnection(Http11Protocol.java:744)
            at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
    int.java:527)
            at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
    kerThread.java:112)
            at java.lang.Thread.run(Thread.java:595)
    Caused by: org.jboss.resource.JBossResourceException: Apparently wrong driver cl
    ass specified for URL: class: com.mysql.jdbc.Driver, url: jdbc:mysql://localhost
    /bookstore
            at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.g
    etDriver(LocalManagedConnectionFactory.java:288)
            at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.c
    reateManagedConnection(LocalManagedConnectionFactory.java:150)
            ... 37 more
      

  6.   

    Context initCtx = new InitialContext();javax.sql.DataSource ds = javax.sql.DataSource)initCtx.lookup(“java:comp/env/jdbc/BookStore”);//error place ! should be “java:comp/env/BookStore”java.sql.Connection conn = ds.getConnection();
      

  7.   

    method two :
    change the jndi-name jdbc/BookStore<jndi-name>BookStore</jndi-name>  //error!!!!
        <connection-url>jdbc:mysql://localhost/bookstore</connection-url>
        <driver-class>com.mysql.jdbc.Driver</driver-class>
        <user-name>root</user-name>
        <password>root</password>
        <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
      

  8.   

    请看这一篇:http://www.myeclipseide.com/index.php?name=PNphpBB2&file=viewtopic&p=11475