1

我在连接 Dynamic Web Project 和数据库 MS Access 时遇到问题。我正在使用 Eclipse Juno 和 Jboss 5.0.0 GA。我知道我必须定义数据源 xml。但我不知道我做错了什么。我将 msaccess-ds.xml 存储在 jboss-5.0.0.GA\server\default\deploy 文件夹中。

<?xml version="1.0" encoding="UTF-8"?>

<!-- ===================================================================== -->
<!--                                                                       -->
<!--  JBoss Server Configuration                                           -->
<!--                                                                       -->
<!-- ===================================================================== -->

<!-- $Id: msaccess-ds.xml 8941 2002-07-22 22:57:24Z d_jencks $ -->
<!-- ==================================================================== -->
<!-- This uses the sun jdbc-odbc driver, so don't expect miracles          -->
<!-- Thanks to Alan Moor, who warns...                                     -->
<!-- Remember, though, never trust critical data, or data that you can't   -->
<!-- afford to lose, or data that you need quick access to, or data that   -->
<!-- needs to be secure, to Microsoft Access.                              -->
<!-- ===================================================================== -->


<datasources>
  <local-tx-datasource>
    <jndi-name>MSAccessDS</jndi-name>
    <!-- format of URL is "jdbc:odbc:DSNNAME" -->
    <connection-url>jdbc:odbc:C:\Users\Tazz\Desktop\bazaAccess\baza niekod\tabele Faelbud całość_wb.mdb</connection-url>
    <driver-class>sun.jdbc.odbc.JdbcOdbcDriver</driver-class>
    <user-name></user-name>
    <password></password>
  </local-tx-datasource>

</datasources>

这是我的 Java 代码:

public static void connectMSAccess(){

        try {
            InitialContext cxt = new InitialContext();
            DataSource ds = (DataSource) cxt.lookup( "java:comp/env/MSAccessDS" );
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

}

这是我的问题:

11:49:34,187 ERROR [STDERR] javax.naming.NameNotFoundException: MSAccessDS not bound
11:49:34,187 ERROR [STDERR]     at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
11:49:34,187 ERROR [STDERR]     at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
11:49:34,187 ERROR [STDERR]     at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
11:49:34,187 ERROR [STDERR]     at org.jnp.server.NamingServer.lookup(NamingServer.java:443)
11:49:34,187 ERROR [STDERR]     at org.jnp.server.NamingServer.lookup(NamingServer.java:399)
11:49:34,187 ERROR [STDERR]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:713)
11:49:34,187 ERROR [STDERR]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:820)
11:49:34,187 ERROR [STDERR]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:673)
11:49:34,187 ERROR [STDERR]     at javax.naming.InitialContext.lookup(Unknown Source)
11:49:34,187 ERROR [STDERR]     at pl.test.connection.MSAccessConnector.connectMSAccess(MSAccessConnector.java:12)
11:49:34,187 ERROR [STDERR]     at pl.test.connection.Serwlet.doGet(Serwlet.java:29)
11:49:34,187 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
11:49:34,187 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
11:49:34,187 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
11:49:34,197 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
11:49:34,197 ERROR [STDERR]     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
11:49:34,197 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
11:49:34,197 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
11:49:34,197 ERROR [STDERR]     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
11:49:34,197 ERROR [STDERR]     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
11:49:34,197 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
11:49:34,197 ERROR [STDERR]     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
11:49:34,197 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
11:49:34,197 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
11:49:34,197 ERROR [STDERR]     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
11:49:34,197 ERROR [STDERR]     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
11:49:34,197 ERROR [STDERR]     at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
11:49:34,197 ERROR [STDERR]     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
11:49:34,197 ERROR [STDERR]     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
11:49:34,197 ERROR [STDERR]     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
11:49:34,197 ERROR [STDERR]     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
11:49:34,197 ERROR [STDERR]     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
11:49:34,197 ERROR [STDERR]     at java.lang.Thread.run(Unknown Source)

我创建了简单的控制台应用程序来连接这个数据库,一切都很好,但我不必使用数据源和 jboss。请帮我!

4

1 回答 1

0

应该context.lookup("java:/MSAccessDS");

于 2013-08-04T10:06:49.993 回答