Re: [JBoss-user] JNDI name for datasource in JBoss2.4.4_Tomcat4.0.1 + MySQL
Thanks a lot. Danch. Now, I am using: ctx.lookup(java:/Customer) and change java:/DefaultDS to java:/Customer, my lookup code works fine. So I assumed if i change java:/Customer back to java:/DefaultDS, I also can lookup for java:/DefaultDS. I will try to use java:comp/env/jdbc/Custmoer and the old setting later. danch wrote: You're close! See comments inline below. -danch Christine wrote: Sorry for miscopy in my previous email! The code in my function is : javax.naming.Context ctx = new InitialContext(); DataSource dbs = (DataSource) ctx.lookup(jdbc/Customer); the name should be java:comp/env/jdbc/Customer. The 'java:comp/env' is the Environment Naming Context that the J2EE spec specifies that the container provide for all components. The res-ref-name of anything you list in an ejb-ref or a resource-ref gets put within that. Connection aConnection = dbs.getConnection(); Statement QStatment = aConnection.createStatement(); ResultSet Result = QStatment.executeQuery(select max(ID) from customer); And I specified the resource reference in both web.xml and jboss-web.xml as following: 1. web.xml resource-ref description The default DS /description res-ref-namejava:/DefaultDS/res-ref-name This is where you say 'jdbc/Customer' res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref 2. jboss-web.xml jboss-web resource-ref res-ref-namejava:/DefaultDS/res-ref-name 'jdbc/Customer' again. res-typejavax.sql.DataSource/res-type jndi-namejdbc/Customer/jndi-name And that's where 'java:/DefaultDS' goes. /resource-ref /jboss-web 3. the JDBC part in jboss.jcml file is: mbean code=org.jboss.jdbc.XADataSourceLoader name=DefaultDomain:service=XADataSource,name=MySQLDS attribute name=PoolNameDefaultDS/attribute attribute name=DataSourceClassorg.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl/attribute attribute name=URLjdbc:mysql://localhost/Customer/attribute attribute name=JDBCUserroot/attribute 4. the jaws.xml file is : jaws datasourcejava:/DefaultDS/datasource type-mappingmySQL/type-mapping Now, I am getting error: jdbc not bound. Would anyone tell me what mistakes I made? Any suggestion will be appreciated! Regards, -- Jia (Christine) Li 524N ICT Building Department of Computer Science University of Calgary ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user -- Jia (Christine) Li 524N ICT Building Department of Computer Science University of Calgary ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] JNDI name for datasource in JBoss2.4.4_Tomcat4.0.1 + MySQL
You're close! See comments inline below. -danch Christine wrote: Sorry for miscopy in my previous email! The code in my function is : javax.naming.Context ctx = new InitialContext(); DataSource dbs = (DataSource) ctx.lookup(jdbc/Customer); the name should be java:comp/env/jdbc/Customer. The 'java:comp/env' is the Environment Naming Context that the J2EE spec specifies that the container provide for all components. The res-ref-name of anything you list in an ejb-ref or a resource-ref gets put within that. Connection aConnection = dbs.getConnection(); Statement QStatment = aConnection.createStatement(); ResultSet Result = QStatment.executeQuery(select max(ID) from customer); And I specified the resource reference in both web.xml and jboss-web.xml as following: 1. web.xml resource-ref description The default DS /description res-ref-namejava:/DefaultDS/res-ref-name This is where you say 'jdbc/Customer' res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref 2. jboss-web.xml jboss-web resource-ref res-ref-namejava:/DefaultDS/res-ref-name 'jdbc/Customer' again. res-typejavax.sql.DataSource/res-type jndi-namejdbc/Customer/jndi-name And that's where 'java:/DefaultDS' goes. /resource-ref /jboss-web 3. the JDBC part in jboss.jcml file is: mbean code=org.jboss.jdbc.XADataSourceLoader name=DefaultDomain:service=XADataSource,name=MySQLDS attribute name=PoolNameDefaultDS/attribute attribute name=DataSourceClassorg.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl/attribute attribute name=URLjdbc:mysql://localhost/Customer/attribute attribute name=JDBCUserroot/attribute 4. the jaws.xml file is : jaws datasourcejava:/DefaultDS/datasource type-mappingmySQL/type-mapping Now, I am getting error: jdbc not bound. Would anyone tell me what mistakes I made? Any suggestion will be appreciated! Regards, -- Jia (Christine) Li 524N ICT Building Department of Computer Science University of Calgary ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] JNDI name for datasource in JBoss2.4.4_Tomcat4.0.1 + MySQL
Why should jdbc/Customer be bound? if your code is in an ejb, you wouldn' link from web.xml or jboss-web.xml but the ejb counterparts. If its in a servlet, looks like you want to look up jdbc/MilosDataSource david jencks On 2002.03.01 18:44:41 -0500 Christine wrote: Hi, Since I didn't get any reply, I am using another approach now. I changed my Customer Entity Bean. I removed the findMaxID method and add a function which uses JDBC connect to Database directly and get the largest ID for that Customer table. But now, I am getting error to find connect to the database. The code in my function is : javax.naming.Context ctx = new InitialContext(); DataSource dbs = (DataSource) ctx.lookup(jdbc/Customer); Connection aConnection = dbs.getConnection(); Statement QStatment = aConnection.createStatement(); ResultSet Result = QStatment.executeQuery(select max(ID) from customer); And I specified the resource reference in both web.xml and jboss-web.xml as following: 1. web.xml resource-ref description The default DS /description res-ref-namejava:/DefaultDS/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref 2. jboss-web.xml jboss-web resource-ref res-ref-namejava:/DefaultDS/res-ref-name res-typejavax.sql.DataSource/res-type jndi-namejdbc/MilosDataSource/jndi-name /resource-ref /jboss-web 3. the JDBC part in jboss.jcml file is: mbean code=org.jboss.jdbc.XADataSourceLoader name=DefaultDomain:service=XADataSource,name=MySQLDS attribute name=PoolNameDefaultDS/attribute attribute name=DataSourceClassorg.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl/attribute attribute name=URLjdbc:mysql://localhost/Milos/attribute attribute name=JDBCUserroot/attribute 4. the jaws.xml file is : jaws datasourcejava:/DefaultDS/datasource type-mappingmySQL/type-mapping Now, I am getting error: jdbc not bound. Would anyone tell me what mistakes I made? Any suggestion will be appreciated! Regards, Hi, I have a finder method which use sub-select as following: findMaxIDWhereClause : ID IN (SELECT MAX(ID) FROM Customer) it works fine when I used IBM WebSphere and DB2. Now I am switching to JBoss + Tomcat + MySQL. Cause MySQL doesn't support sub-select. Does anyone know whether there is some other way to get my findMaxIDWhereClause work without have to change code? Thanks in advance! regards, -- Jia (Christine) Li 524N ICT Building Department of Computer Science University of Calgary ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user -- Jia (Christine) Li 524N ICT Building Department of Computer Science University of Calgary ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] JNDI name for datasource in JBoss2.4.4_Tomcat4.0.1 + MySQL
I am sorry to confuse you by my mistake. I have a database in MySQL called Customer, which is specified in jboss.jcml. mbean code=org.jboss.jdbc.XADataSourceLoader name=DefaultDomain:service=XADataSource,name=MySQLDS attribute name=PoolNameDefaultDS/attribute attribute name=DataSourceClassorg.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl/attribute attribute name=URLjdbc:mysql://localhost/Customer/attribute Now, I wanted to use bind my database Customer to JNDI server with name jdbc/customer and then I can use JDBC connect to my database from my EJB code. So my question is how I should specify deploy descriptors to bind database Customer to JNDI server? David Jencks wrote: Why should jdbc/Customer be bound? if your code is in an ejb, you wouldn' link from web.xml or jboss-web.xml but the ejb counterparts. If its in a servlet, looks like you want to look up jdbc/MilosDataSource david jencks On 2002.03.01 18:44:41 -0500 Christine wrote: Hi, Since I didn't get any reply, I am using another approach now. I changed my Customer Entity Bean. I removed the findMaxID method and add a function which uses JDBC connect to Database directly and get the largest ID for that Customer table. But now, I am getting error to find connect to the database. The code in my function is : javax.naming.Context ctx = new InitialContext(); DataSource dbs = (DataSource) ctx.lookup(jdbc/Customer); Connection aConnection = dbs.getConnection(); Statement QStatment = aConnection.createStatement(); ResultSet Result = QStatment.executeQuery(select max(ID) from customer); And I specified the resource reference in both web.xml and jboss-web.xml as following: 1. web.xml resource-ref description The default DS /description res-ref-namejava:/DefaultDS/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref 2. jboss-web.xml jboss-web resource-ref res-ref-namejava:/DefaultDS/res-ref-name res-typejavax.sql.DataSource/res-type jndi-namejdbc/MilosDataSource/jndi-name /resource-ref /jboss-web 3. the JDBC part in jboss.jcml file is: mbean code=org.jboss.jdbc.XADataSourceLoader name=DefaultDomain:service=XADataSource,name=MySQLDS attribute name=PoolNameDefaultDS/attribute attribute name=DataSourceClassorg.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl/attribute attribute name=URLjdbc:mysql://localhost/Milos/attribute attribute name=JDBCUserroot/attribute 4. the jaws.xml file is : jaws datasourcejava:/DefaultDS/datasource type-mappingmySQL/type-mapping Now, I am getting error: jdbc not bound. Would anyone tell me what mistakes I made? Any suggestion will be appreciated! Regards, Hi, I have a finder method which use sub-select as following: findMaxIDWhereClause : ID IN (SELECT MAX(ID) FROM Customer) it works fine when I used IBM WebSphere and DB2. Now I am switching to JBoss + Tomcat + MySQL. Cause MySQL doesn't support sub-select. Does anyone know whether there is some other way to get my findMaxIDWhereClause work without have to change code? Thanks in advance! regards, -- Jia (Christine) Li 524N ICT Building Department of Computer Science University of Calgary ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user -- Jia (Christine) Li 524N ICT Building Department of Computer Science University of Calgary ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user -- Jia (Christine) Li 524N ICT Building Department of Computer Science University of Calgary ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user