Den Zugriff auf die Datenquelle ein, aus der stand-alone-Anwendung

Ich habe die Datenquelle in Websphere-server, und sein name ist myDataSource - (JNDI-name ist oracleDS). Jetzt will ich auf Sie durch die stand-alone-Anwendung.

Schrieb ich den Balg-code, um den Zugriff auf die Daten sorce.

Hashtable<String, String> pdEnv = new Hashtable<String, String>();
pdEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
pdEnv.put(Context.PROVIDER_URL, "iiop://localhost:2809");

Context initialContext = new InitialContext(pdEnv);

DataSource dataSource = (DataSource) initialContext
                    .lookup("java:comp/env/jdbc/oracleDS");

Aber wenn ich die Anwendung ausführen, ich bin immer der Balg Ausnahme.

Aug 6, 2013 11:33:41 PM null null
SEVERE: javaAccessorNotSet
javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.

Bitte lassen Sie mich wissen, habe ich zu tun alle änderungen an der Konfiguration in websphere Zugriff auf die Daten-Quelle oder jeder andere code-Ebene änderungen habe ich zu tun?

Bitte bestätigen Sie mir, können wir den Zugriff auf die datasource, die von außerhalb des Containers(websphere)?

Update1:

Ich followd der Weg, den PhilipJ erwähnt. Dann bin ich gtting der Balg Ausnahme.

SEVERE: Cannot get connection: javax.naming.NameNotFoundException: Context: LTC-VIRTUS-24WZNode01Cell/nodes/LTC-VIRTUS-24WZNode01/servers/server1, name: jdbc/oracleDS: First component in name oracleDS not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
javax.naming.NameNotFoundException: Context: LTC-VIRTUS-24WZNode01Cell/nodes/LTC-VIRTUS-24WZNode01/servers/server1, name: jdbc/oracleDS: First component in name oracleDS not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
    at com.ibm.ws.naming.jndicos.CNContextImpl.mapNotFoundException(CNContextImpl.java:4365)
    at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1794)
    at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1749)
    at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1500)
    at com.ibm.ws.naming.jndicos.CNContextImpl.lookup(CNContextImpl.java:637)
    at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:165)
    at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179)
    at javax.naming.InitialContext.lookup(InitialContext.java:436)
    at com.nyl.connection.ConnectionUtil.getConnection(ConnectionUtil.java:38)
    at com.nyl.main.Main.main(Main.java:9)
Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
    at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:95)
    at com.ibm.WsnOptimizedNaming._NamingContextStub.resolve_complete_info(_NamingContextStub.java:506)
    at com.ibm.ws.naming.jndicos.CNContextImpl$2.run(CNContextImpl.java:2797)
    at com.ibm.ws.naming.jndicos.CNContextImpl$2.run(CNContextImpl.java:2793)
    at com.ibm.ws.naming.util.CommonHelpers.retry(CommonHelpers.java:763)
    at com.ibm.ws.naming.jndicos.CNContextImpl.cosResolve(CNContextImpl.java:2791)
    at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1790)
    ... 8 more

Update2:

Fand ich den Weg zu vermeiden die Ausnahme. Der code sollte Balg,

Hashtable<String, String> pdEnv = new Hashtable<String, String>();
pdEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
pdEnv.put(Context.PROVIDER_URL, "iiop://localhost:2809");

Context initialContext = new InitialContext();
DataSource datasource = (DataSource) initialContext.lookup("oracleDS");

if (datasource != null) {
connection = datasource.getConnection("admin","admin");
} else {
LOGGER.info("Failed to lookup datasource.");
}

Aber das problem hier ist, gebe ich die Datenbank credintials creat die Verbindung. Ich will nicht, es zu geben. Kann irgend jemand bitte lassen Sie mich wissen, wie Sie die Verbindung zu erstellen, ohne dass die Datenbank credintials?

vielleicht ? www-01.ibm.com/support/docview.wss?uid=swg21580598
Dank Gesehen. Ich habe versucht, Ihre Lösung, aber immer das gleiche Problem.
Sie können die logischen Namen in diesem Fall (java:comp...), müssen Sie die real-JNDI-name der Ressource. Überprüfen Sie in der Admin-Konsole.
Ich habe nur den JNDI-Namen, dann habe ich nicht den obigen Fehler aber wenn ich Schaffe die Verbindung, die ich bin immer "EVERE: Cannot get connection: java.sql.SQLException: ungültige Argumente in callDSRA0010E: SQL-Status = null, Error-Code = 17,433" Ausnahme.

InformationsquelleAutor Java-Seekar | 2013-08-07

Schreibe einen Kommentar