-
1. Re: Unable to get a DataSource in a servlet
sesques Apr 28, 2004 2:32 PM (in response to offline)Try:
For mysql-ds.xml :<datasources> <local-tx-datasource> <jndi-name>MySQLDS</jndi-name> <connection-url>jdbc:mysql://192.168.1.50:3306/webapp</connection-url> <driver-class>org.gjt.mm.mysql.Driver</driver-class> <user-name>x</user-name> <password>y</password> </local-tx-datasource> </datasources>
for web.xml :<resource-ref> <description>The default DS</description> <res-ref-name>MySQLDS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
for jboss-web.xml :<resource-ref> <res-ref-name>MySQLDS</res-ref-name> <jndi-name>java:/MySQLDS</jndi-name> </resource-ref>
and code:Context initialContext = new InitialContext(); Context env = (Context) initialContext.lookup("java:comp/env"); DataSource ds = (DataSource) env.lookup("MySQLDS");
I Hope it helps -
2. Re: Unable to get a DataSource in a servlet
offline Apr 28, 2004 3:24 PM (in response to offline)It does, although i'd like to know why -- what was it that i was doing wrong in my naming?
In a slightly related note, where should i be putting the driver jar file for this? I'm getting a ClassNotFoundException when i try to initialize the connection, so obviously i'm going about it wrong. My mysql driver jar file is currently in $JBOSS_HOME/lib -
3. Re: Unable to get a DataSource in a servlet
rupshall Apr 28, 2004 3:27 PM (in response to offline)I have my jdbc jar file in $JBOSS_HOME/servers/default/lib, it needs to be in the lib under whatever server you are using.
-
4. Re: Unable to get a DataSource in a servlet
offline Apr 28, 2004 3:52 PM (in response to offline)Thanks :)
I figured that one out with embarassingly little googling. Silly me.
At any rate, i still don't know what i was doing wrong in web.xml and jboss-web.xml. I'd love to hear, though. -
5. Re: Unable to get a DataSource in a servlet
sesques Apr 29, 2004 3:28 AM (in response to offline)1) The <res-ref-name> in web.xml and jboss-web.xml must be the same.
2) According to your mysql-ds.xml, the jndi name for your datasource is java:/MySQLDS at deployment time because the comp/env environment is not yet set.
3) Then, in your servlet, the lookup mus be done in java:comp/env/<res-ref-name>
Is this what you want ot know ?