Re: Data Sources Help
Congratulations Mark, and thanks for the summary! I hadn't looked at how to do that very last line of code yet, I'm happy to see it is so straight-forward. Gary On Yesterday, Mark ([EMAIL PROTECTED]) wrote: Fixed it! Yay! Gary, I tried it again per the suggestion you forwarded from support, but this time by removing the resource-ref from my web.xml and coding my Java as you noted: "jdbc/etc". Also fixed the startup problem by removing a transparently stupid syntax error from data-sources.xml. In case anybody else has been following this thread, here's the working data-source and a code fragment: data-source name="Oracle data source" class="com.evermind.sql.ConnectionDataSource" location="jdbc/OracleDS" pooled-location="jdbc/OraclePooledDS" xa-location="jdbc/xa/OracleXADS" ejb-location="jdbc/OracleEJBDS" url="jdbc:oracle:thin:@dracula.smartmonsters.com:1521:DEV" connection-driver="oracle.jdbc.driver.OracleDriver" username="foo" password="bar" schema="database-schemas/oracle.xml" / InitialContext cxt = new InitialContext(); // WRONG: DataSource ds = (DataSource) cxt.lookup("java:comp/env/OracleDS"); DataSource ds = (DataSource) cxt.lookup("jdbc/OracleEJBDS"); // RIGHT Connection c = ds.getConnection(); So the moral of the story seems to be, don't use the syntax "java:comp/env/myDS"; rather, use "jdbc/myDS". Note I've substituted "OracleEJBDS" per the note from support which Gary included earlier in the thread. Finally -- 'cause I'm personally done with this thread for a while, ;-) -- if any of the Evermind folks are taking note, I'd very much like to be able to choose to use networked LDAP for objects such as DataSources. Please consider this an enhancement suggestion. Thanks Gary, Allen and Deepak! --Mark
RE: Data Sources Help
On that note, we use several databases. How is this handled? We have a QA database for testing that our qa machines need to be set up to, but we also use two databases at one time for two-phase commit transactions. Is it possible to set up a datasource for two databases and have connections for both? Or is that not supported by J2EE? -Original Message- From: David Kenzik [mailto:[EMAIL PROTECTED]] Sent: Sunday, October 22, 2000 7:17 PM To: Orion-Interest Subject: Data Sources Help Can anyone provide a step-by-step 'hello world' procedure for setting up data-sources.xml properly and calling the resource from within a servlet? Alternatively, can someone review my setup and comment on what might be wrong? The section of my data-sources.xml looks like this: data-source class="com.evermind.sql.DriverManagerDataSource" name="jdbc/d123DS" location="jdbc/d123DS" xa-location="jdbc/xa/d123XADS" ejb-location="jdbc/d123DS" connection-driver="oracle.jdbc.driver.OracleDriver" username="username" password="password" url="jdbc:oracle:thin:my.oracle.host:@dev2:1521:D123DEV" inactivity-timeout="30" / I'm attempting to create a connection within my servlet. Snippets of the relevant code: public class DSTest extends HttpServlet { InitialContext ctx; DataSource ds; ... public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); try { ctx=new InitialContext(); ds = (DataSource) ctx.lookup("java:comp/env/jdbc/d123DS"); con = ds.getConnection(); ... } ... catch (NamingException e) { System.out.println(e); } } It is catching the NamingException, telling me: javax.naming.NamingException: Error instantiating web-app JNDI-context: No location specified for resource-ref d123DS So I went and added to my application's web.xml, since this isn't under the default orion application: context-param param-named123DS/param-name param-valuejdbc/d123DS/param-value /context-param resource-ref descriptionTest Data Source/description res-ref-named123DS/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref And it still catches the same exception. Am I missing something simple? I'll gladly write up a tutorial for this for orionsupport.com if I can get this working. My environment: jdk 1.3, orion 1.4.0 Any help would be wonderful. -- David S. Kenzik [EMAIL PROTECTED] - http://kenzik.com Original Music - http://mp3.com/text
Re: Data Sources Help
On Today, David Kenzik ([EMAIL PROTECTED]) wrote: Yes, Greg Matthews sent me a note shortly after receiving my inquiry with that same answer-- this is the case, "java:comp/env/jdbc..." won't work, you must shorten it to simply "jdbc/SOURCENAME". Now that is out of the way, and it __was__ working for a bit. Really! However, I wanted to restart Orion and pass it some debugging info to find a pesky connection leak. Now my Orion won't startup: Error initializing server: DriverManagerDataSource driver 'oracle.jdbc.driver.OracleDriver' not found I've changed nothing and can't figure out what the heck would've caused this. Weird. Are you running 1.3.8? I wish I had a clue but I don't :( Gary
Re: Data Sources Help
On Today, Mark ([EMAIL PROTECTED]) wrote: Dunno if this is any help, but I found through experimentation that, if you're using the deployment approach suggested by Deepak Goel in the thread "ANSWER: how to use pooled connections in Orion", the parameter to pass to InitialContext.lookup() is, as he notes, "java:comp/env/d123DS", not "java:comp/env/jdbc/d123DS". That is, there's no "jdbc" in that String. Just pointing that out because I missed it at first. (Yes, it seems to take a while for messages to get out to the list!) --Mark Mark, what version of Orion are you using? I wrote a little utility that traverses the JNDI namespace, just looking for Context objects and displaying what's in them. I found an env Context but it was empty! I did eventually discover, due to a chance remark of someone on the list, that there is in fact another Context which my scheme did not find, namely jdbc/*. I'm feeling pretty stupid about JNDI these days, since I can't even figure out how to search the space, despite the spec's indication that (as best I can tell) it's a purely heirarchical namespace! Gary
Re: Data Sources Help
Gary Shea said... On Today, David Kenzik ([EMAIL PROTECTED]) wrote: Error initializing server: DriverManagerDataSource driver 'oracle.jdbc.driver.OracleDriver' not found I've changed nothing and can't figure out what the heck would've caused this. Weird. Are you running 1.3.8? I wish I had a clue but I don't :( Naw, running 1.4.0. I couldn't figure it out so I reinstalled from scratch. I can only assume that a config file became corrupted to Orion somehow, although I couldn't find anything reflecting that. -- David S. Kenzik [EMAIL PROTECTED] - http://kenzik.com Original Music - http://mp3.com/text
Re: Data Sources Help
Gary, I'm running 1.3.8. Per your research into the Orion JNDI namespace, could there be an undocumented quirk in Orion's implementation? I've been using JNDI/LDAP pretty extensively the last couple months and have been super impressed with its ease and speed. But, that environment is under my programmatic control, including the namespace design. In fact what I'd really like to be able to do is throw a configuration switch enabling a networked LDAP server as an alternative to using the Orion JNDI namespace. If there were a JNDI.xml file or something like that, perhaps it would be possible to organize the namespace in a way that makes best sense for your enterprise application architecture; and of course other servers would be able to share centralized resources. To my thinking DataSources kind of cry out for this approach. Seems to be the J2EE "way", although, I dunno, I'm still learning. In case it helps, below are the entries in my data-sources.xml and web.xml files, and a code example. These are taken directly from Deepak's earlier posts. With these I'm able to get a non-null Connection reference from the DataSource. But note this isn't to declare victory: still have a strange bug to figure out. My tag handler blows up with a NullPointerException when I call Connection.createStatement() on the Connection reference. Have no idea if this is related to the config below, or what, but the Exception is being caught by Orion, not by my tag handler, which at first glance points to Orion's implementation of the pooled Connection object. Note to Mike Cannon-Brookes: based on the quantity of questions posted to the mailing list, I'd suggest that proper configuration of DataSources and also the workings of the Orion JNDI namespace are two good candidates for your super-FAQ suggestion. :-) --Mark From data-sources.xml: !-- NON-POOLED Oracle data source -- data-source class="com.evermind.sql.DriverManagerDataSource" name="OracleNP" location="jdbc/OracleNP" xa-location="jdbc/xa/OracleXANP" ejb-location="jdbc/OracleNP" connection-driver="oracle.jdbc.driver.OracleDriver" username="foo" password="bar" url="jdbc:oracle:thin:@test:1521:DEV" inactivity-timeout="30" schema="database-schemas/oracle.xml" / !-- POOLED Oracle data source -- data-source class="com.evermind.sql.OrionPooledDataSource" name="OracleDS" location="jdbc/OracleDS" xa-location="jdbc/xa/OracleXADS" ejb-location="jdbc/OracleDS" max-connections="10" source-location="jdbc/OracleNP" pooled-location="jdbc/OracleDS" connection-driver="oracle.jdbc.driver.OracleDriver" username="foo" password="bar" url="jdbc:oracle:thin:@test:1521:DEV" inactivity-timeout="30" schema="database-schemas/oracle.xml" / From web.xml: context-param param-nameOracleDS/param-name param-valuejdbc/OracleDS/param-value /context-param resource-ref descriptionOracle pooled data source/description res-ref-nameOracleDS/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref From the tag handler: try { InitialContext cxt = new InitialContext(); DataSource ds = (DataSource) cxt.lookup("java:comp/env/OracleDS"); Connection c = ds.getConnection(); if (c == null) System.out.println("== Connection is null"); else System.out.println("Connection is not null"); /* Blows up here with NullPointerException caught by Orion -- NOT caught by the enclosing try/catch block. Is this a bug in the Connection object, which I assume is Orion's implementation of a pooled version? Should I post all this to Buzilla? Dunno!: */ Statement s = c.createStatement(); if (s == null) System.out.println("== Statement is null"); else System.out.println("Statement is not null"); } catch (Exception e) { System.err.println("== Caught: " + e); } == Mark, what version of Orion are you using? I wrote a little utility that traverses the JNDI namespace, just looking for Context objects and displaying what's in them. I found an env Context but it was empty! I did eventually discover, due to a chance remark of someone on the list, that there is in fact another Context which my scheme did not find, namely jdbc/*. I'm feeling pretty stupid about JNDI these days, since I can't even figure out how to search the space, despite the spec's indication that (as best I can tell) it's a purely heirarchical namespace! Gary On Today, Mark ([EMAIL PROTECTED]) wrote: Dunno if this is any help, but I found through experimentation that, if you're using the deployment approach suggested by Deepak Goel in the thread "ANSWER: how to use pooled connections in Orion", the parameter to pass to InitialContext.lookup() is, as he notes, "java:comp/env/d123DS", not
Re: Data Sources Help
Caught: " + e); } == Mark, what version of Orion are you using? I wrote a little utility that traverses the JNDI namespace, just looking for Context objects and displaying what's in them. I found an env Context but it was empty! I did eventually discover, due to a chance remark of someone on the list, that there is in fact another Context which my scheme did not find, namely jdbc/*. I'm feeling pretty stupid about JNDI these days, since I can't even figure out how to search the space, despite the spec's indication that (as best I can tell) it's a purely heirarchical namespace! Gary On Today, Mark ([EMAIL PROTECTED]) wrote: Dunno if this is any help, but I found through experimentation that, if you're using the deployment approach suggested by Deepak Goel in the thread "ANSWER: how to use pooled connections in Orion", the parameter to pass to InitialContext.lookup() is, as he notes, "java:comp/env/d123DS", not "java:comp/env/jdbc/d123DS". That is, there's no "jdbc" in that String. Just pointing that out because I missed it at first. (Yes, it seems to take a while for messages to get out to the list!) --Mark === Are your Drivers available? is your Datasource defined correctly? Here is my file and it works fine for me ?xml version="1.0"? !DOCTYPE data-sources PUBLIC "Orion data-sources" "http://www.orionserver.com/dtds/data-sources.dtd" data-sources !-- An example/default DataSource that uses an ordinary JDBC-driver (in this case hsql) to create the connections. This tag creates all the needed kinds of data-sources, transactional, pooled and EJB-aware sources. The source generally used in application code is the "EJB" one - it provides transactional safety and connection pooling. -- data-source class="com.evermind.sql.DriverManagerDataSource" name="Oracle" location="jdbc/RedbookDS" xa-location="jdbc/xa/RedbookXADS" ejb-location="jdbc/RedbookDS" connection-driver="oracle.jdbc.driver.OracleDriver" username="user" password="password" url="jdbc:oracle:thin:@enterprise:1521:database" inactivity-timeout="30" / /data-sources With of course the exception of changing the user and password and databse schema. :) - Original Message - From: "Mark" [EMAIL PROTECTED] To: "Orion-Interest" [EMAIL PROTECTED] Sent: Monday, October 23, 2000 5:16 PM Subject: Re: Data Sources Help Thanks Gary. Well I gave it a shot. First thing to note is that the instructions you were given by support seem to be self contradictory. While suggesting you should use com.evermind.OrionConnectionDataSource with Oracle, the example data-source uses com.evermind.sql.ConnectionDataSource. So I tried them both, and at least in my environment they blow up with identical errors when the server is started: Result with com.evermind.sql.ConnectionDataSource: java -jar orion.jar java.lang.NullPointerException at com.evermind.server.deployment.EnterpriseArchive.ajv(JAX) at com.evermind.server.deployment.EnterpriseArchive.bx(JAX) at com.evermind.xml.XMLConfig.bs(JAX) at com.evermind.xml.XMLConfig.ay(JAX) at com.evermind.xml.XMLConfig.ay(JAX) at com.evermind.server.ServerComponent.ay(JAX) at com.evermind.server.XMLApplicationServerConfig.ak9(JAX) at com.evermind.server.XMLApplicationServerConfig.by(JAX) at com.evermind.xml.XMLConfig.ay(JAX) at com.evermind.xml.XMLConfig.ay(JAX) at com.evermind.server.hc.run(JAX) at java.lang.Thread.run(Thread.java:498) at com.evermind.util.f.run(JAX) Result with com.evermind.OrionConnectionDataSource: java -jar orion.jar java.lang.NullPointerException at com.evermind.server.deployment.EnterpriseArchive.ajv(JAX) at com.evermind.server.deployment.EnterpriseArchive.bx(JAX) at com.evermind.xml.XMLConfig.bs(JAX) at com.evermind.xml.XMLConfig.ay(JAX) at com.evermind.xml.XMLConfig.ay(JAX) at com.evermind.server.ServerComponent.ay(JAX) at com.evermind.server.XMLApplicationServerConfig.ak9(JAX) at com.evermind.server.XMLApplicationServerConfig.by(JAX) at com.evermind.xml.XMLConfig.ay(JAX) at com.evermind.xml.XMLConfig.ay(JAX) at com.evermind.server.hc.run(JAX) at java.lang.Thread.run(Thread.java:498) at com.evermind.util.f.run(JAX) So... hmmm... Will keep trying as time permits. --Mark
Data Sources Help
Can anyone provide a step-by-step 'hello world' procedure for setting up data-sources.xml properly and calling the resource from within a servlet? Alternatively, can someone review my setup and comment on what might be wrong? The section of my data-sources.xml looks like this: data-source class="com.evermind.sql.DriverManagerDataSource" name="jdbc/d123DS" location="jdbc/d123DS" xa-location="jdbc/xa/d123XADS" ejb-location="jdbc/d123DS" connection-driver="oracle.jdbc.driver.OracleDriver" username="username" password="password" url="jdbc:oracle:thin:my.oracle.host:@dev2:1521:D123DEV" inactivity-timeout="30" / I'm attempting to create a connection within my servlet. Snippets of the relevant code: public class DSTest extends HttpServlet { InitialContext ctx; DataSource ds; ... public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); try { ctx=new InitialContext(); ds = (DataSource) ctx.lookup("java:comp/env/jdbc/d123DS"); con = ds.getConnection(); ... } ... catch (NamingException e) { System.out.println(e); } } It is catching the NamingException, telling me: javax.naming.NamingException: Error instantiating web-app JNDI-context: No location specified for resource-ref d123DS So I went and added to my application's web.xml, since this isn't under the default orion application: context-param param-named123DS/param-name param-valuejdbc/d123DS/param-value /context-param resource-ref descriptionTest Data Source/description res-ref-named123DS/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref And it still catches the same exception. Am I missing something simple? I'll gladly write up a tutorial for this for orionsupport.com if I can get this working. My environment: jdk 1.3, orion 1.4.0 Any help would be wonderful. -- David S. Kenzik [EMAIL PROTECTED] - http://kenzik.com Original Music - http://mp3.com/text
Re: Data Sources Help
On Today, David Kenzik ([EMAIL PROTECTED]) wrote: ds = (DataSource) ctx.lookup("java:comp/env/jdbc/d123DS"); Well, it took me a couple weeks (not full time!) to figure out that even though they tell you to use java:comp/env/jdbc... it doesn't actually work. Instead do your lookup on just "jdbc/d123DS". At least, that's what worked for me... Gary -- David S. Kenzik [EMAIL PROTECTED] - http://kenzik.com Original Music - http://mp3.com/text
Re: Data Sources Help
Gary Shea said... On Today, David Kenzik ([EMAIL PROTECTED]) wrote: ds = (DataSource) ctx.lookup("java:comp/env/jdbc/d123DS"); Well, it took me a couple weeks (not full time!) to figure out that even though they tell you to use java:comp/env/jdbc... it doesn't actually work. Instead do your lookup on just "jdbc/d123DS". Yes, Greg Matthews sent me a note shortly after receiving my inquiry with that same answer-- this is the case, "java:comp/env/jdbc..." won't work, you must shorten it to simply "jdbc/SOURCENAME". Now that is out of the way, and it __was__ working for a bit. Really! However, I wanted to restart Orion and pass it some debugging info to find a pesky connection leak. Now my Orion won't startup: Error initializing server: DriverManagerDataSource driver 'oracle.jdbc.driver.OracleDriver' not found I've changed nothing and can't figure out what the heck would've caused this. My oracle.zip jdbc drivers are available because if I comment out my data-sources tag and start Orion, my servlets that use the Oracle jdbc driver directly (without the Orion driver manager) work just fine. I'm totally boggled at this point. Any ideas? Also, does anyone else notice that it takes nearly an hour for messages to make it to the list distribution, or is it just my location versus the Evermind mail server I guess I'm used to instant email. ;-) -- David S. Kenzik [EMAIL PROTECTED] - http://kenzik.com Original Music - http://mp3.com/text