Tomcat and JNDI
Hello, I am trying to get tomcat and jndi working. I am just looking for some direction in troubleshooting. I have configured the server.xml and web.xml as given in the examples of the tomcat docs for oracle. In the code I am trying to get working. //snippet// initNamingContext= new InitialContext (); envNamingContext= (Context) initNamingContext.lookup ("java:comp/env"); envNamingContext.bind (JNDINames.userDataDtdJndiName, userDataDTDName); When it does the envNamingContext.bind it throws and exception (see below) Any help would be greatly appreciated Thanks Randy Paries javax.naming.NamingException: Context is read only at org.apache.naming.NamingContext.checkWritable(NamingContext.java:942) at org.apache.naming.NamingContext.bind(NamingContext.java:870) at org.apache.naming.NamingContext.bind(NamingContext.java:212) at org.apache.naming.NamingContext.bind(NamingContext.java:228) at com.mc.pc.struts.plugins.PrintCenterPlugin.init(PrintCenterPlugin.java:1 10) at org.apache.struts.action.ActionServlet.initApplicationPlugIns(ActionServ let.java:991) at org.apache.struts.action.ActionServlet.init(ActionServlet.java:471) at com.mc.action.MCActionServlet.init(MCActionServlet.java:22) at javax.servlet.GenericServlet.init(GenericServlet.java:258) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.jav a:918) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:810) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.j ava:3279) at org.apache.catalina.core.StandardContext.start(StandardContext.java:3421 ) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1123) at org.apache.catalina.core.StandardHost.start(StandardHost.java:638) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1123) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:343) at org.apache.catalina.core.StandardService.start(StandardService.java:388) at org.apache.catalina.core.StandardServer.start(StandardServer.java:506) at org.apache.catalina.startup.Catalina.start(Catalina.java:781) at org.apache.catalina.startup.Catalina.execute(Catalina.java:681) at org.apache.catalina.startup.Catalina.process(Catalina.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Impl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:243) DEBUG [01-13-03 12:56:28,750] mc.servlets.MCContextListener.contextInitialized():28 : ServletContext Listener was Called P:\webapp\ -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
Tomcat and JNDI - Basic Question
In the tomcat documentation it is said that to configure a new JNDI resource you shoul put a Resource entry in the Context portion of my app, and a following ResourceParams, indicating the java class name of the factory (the class that must implement ObjectFactory). This seems quite correct: in order to build an object, I need a Factory!! But I noticed it works fine even if the ResourceParams is not present ?? The conclusion is: I'm surely missing something !! How can Tomcat know how to build my object if I don't give the name of the factory class ??? Any Help Appreciated!! Renato Renato Romano Sistemi e Telematica S.p.A. Calata Grazie - Vial Al Molo Giano 16127 - GENOVA e-mail: [EMAIL PROTECTED] Tel.: 010 2712603 _ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Tomcat and JNDI - Basic Question
In the tomcat documentation it is said that to configure a new JNDI resource you should put a Resource entry in the Context portion of my app, and a following ResourceParams, indicating the java class name of the factory (the class that must implement ObjectFactory). This seems quite correct: in order to build an object, I need a Factory!! But I noticed it works fine even if the ResourceParams is not present ?? The conclusion is: I'm surely missing something !! How can Tomcat know how to build my object if I don't give the name of the factory class ??? Any Help Appreciated!! Renato Renato Romano Sistemi e Telematica S.p.A. Calata Grazie - Vial Al Molo Giano 16127 - GENOVA e-mail: [EMAIL PROTECTED] Tel.: 010 2712603 _ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Apache, Tomcat and JNDI problem...
Hi, I have been developing an application that does a JNDI lookup for a DataSource and then does a database query. Everything works great when I just use Tomcat 4.0.1. But when I use Apache as the front end and use the Warp Connector to connect Apache and Tomcat, I am then unable to retrieve the DataSource from the JNDI tree. I receive the exception: javax.naming.NameNotFoundException: Name testDB is not bound in this Context I did some digging and found that there is the same problem with the Tomcat example: /examples/servlet/JndiServlet This is what I receive when running the example using only Tomcat on port 8080: (http://localhost:8080/examples/servlet/JndiServlet) Simple lookup test : Max exemptions value : 15 list() on /comp/env Context : Binding : mail: org.apache.naming.NamingContext Binding : maxExemptions: java.lang.Integer Binding : minExemptions: java.lang.Integer Binding : jdbc: org.apache.naming.NamingContext Binding : ejb: org.apache.naming.NamingContext Binding : name3: java.lang.Integer Binding : foo: org.apache.naming.NamingContext listBindings() on /comp/env Context : Binding : mail: org.apache.naming.NamingContext:org.apache.naming.NamingContext@7a1bb6 Binding : maxExemptions: java.lang.Integer:15 Binding : minExemptions: java.lang.Integer:1 Binding : jdbc: org.apache.naming.NamingContext:org.apache.naming.NamingContext@315d34 Binding : ejb: org.apache.naming.NamingContext:org.apache.naming.NamingContext@5e256f Binding : name3: java.lang.Integer:1 Binding : foo: org.apache.naming.NamingContext:org.apache.naming.NamingContext@6bd8ea But when I connect Apache and Tomcat using the Warp Connector I receive: (http://localhost/examples/servlet/JndiServlet) JNDI lookup failed : javax.naming.NameNotFoundException: Name maxExemptions is not bound in this Context list() on /comp/env Context : Binding : mail: org.apache.naming.NamingContext Binding : minExemptions: java.lang.Integer Binding : ejb: org.apache.naming.NamingContext Binding : name3: java.lang.Integer Binding : foo: org.apache.naming.NamingContext listBindings() on /comp/env Context : Binding : mail: org.apache.naming.NamingContext:org.apache.naming.NamingContext@2da3d Binding : minExemptions: java.lang.Integer:1 Binding : ejb: org.apache.naming.NamingContext:org.apache.naming.NamingContext@45f743 Binding : name3: java.lang.Integer:1 Binding : foo: org.apache.naming.NamingContext:org.apache.naming.NamingContext@6c8909 I have tested this on Apache 1.3.20, Apache 1.3.22, Tomcat 4.0, Tomcat 4.0.1 and Tomcat 4.1-dev (nightly build). Has anyone come across this problem before, or know how to correct this? Justin.
Re: Tomcat and JNDI - Basic Question
Howdy, It might be that the fallback behavior is to use a public no-args constructor, ala JavaBeans. Yoav Shapira --- Renato Romano <[EMAIL PROTECTED]> wrote: > In the tomcat documentation it is said that to configure a new JNDI > resource you should put a Resource entry in the Context portion of my > app, and a following ResourceParams, indicating the java class name of > the factory (the class that must implement ObjectFactory). This seems > quite correct: in order to build an object, I need a Factory!! But I > noticed it works fine even if the ResourceParams is not present ?? The > conclusion is: I'm surely missing something !! How can Tomcat know how > to build my object if I don't give the name of the factory class ??? > > > > > > > > Any Help Appreciated!! > Renato > > > Renato Romano > Sistemi e Telematica S.p.A. > Calata Grazie - Vial Al Molo Giano > 16127 - GENOVA > > e-mail: [EMAIL PROTECTED] > Tel.: 010 2712603 > _ > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > = Yoav Shapira [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Problem connecting to mysql database with Tomcat and JNDI
Folks, I'm having trouble connecting to a mysql database through Tomcat. I'm using Tomcat 5.0.9a with mysql 4.0.14. I have the mysql 3.0.8 JDBC driver in ${TOMCAT_HOME}/common/lib. I'm running RedHat 8.0 with a stock kernel. I've been able to connect to the database without JNDI services. I believe I have the database user set up correctly. I have been all over the web trying to figure out what the problem is. It seems like everyone is having this problem, but no two solutions are the same. FWIW I've tried a lot of this on Tomcat 4 and have had the same results. I've traced the problem to the following code from the JSP file below: conn = ds.getConnection(); Any thoughts/ideas would be greatly appreciated. I'm at the end of my rope on this. Here is the error message I'm getting. java.lang.NullPointerException org.apache.jsp.usingDataSource_jsp._jspService(usingDataSource_jsp.java:74) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) Here is the JSP page I'm using: <[EMAIL PROTECTED] import="java.sql.*, javax.sql.*, javax.naming.*"%> Using a DataSource Using a DataSource <% DataSource ds = null; Connection conn = null; ResultSet result = null; Statement stmt = null; ResultSetMetaData rsmd = null; try { Context context = new InitialContext(); Context envCtx = (Context) context.lookup("java:comp/env"); ds = (DataSource)envCtx.lookup("jdbc/address"); if (ds != null) { conn = ds.getConnection(); stmt = conn.createStatement(); result = stmt.executeQuery("SELECT * FROM AddressList"); } } catch (SQLException e) { System.out.println("Error occurred " + e); } int columns = 0; try { rsmd = result.getMetaData(); // bad line columns = rsmd.getColumnCount(); } catch (SQLException e) { System.out.println("Error occurred " + e); } %> <% // write out the header cells containing the column labels try { for (int i = 1; i <= columns; i++) { out.write("" + rsmd.getColumnLabel(i) + ""); } %> <% // now write out one row for each entry in the database table while (result.next()) { out.write(""); for (int i = 1; i <= columns; i++) { out.write("" + result.getString(i) + ""); } out.write(""); } // close the connection, resultset, and the statement result.close(); stmt.close(); conn.close(); } // end of the try block catch (SQLException e) { System.out.println("Error " + e); } // ensure everything is closed finally { try { if (stmt != null) { stmt.close(); } } catch (SQLException e) {} try { if (conn != null) { conn.close(); } } catch (SQLException e ) {} } %> Here are the changes I made to my server.xml file. Of course, I've changed the username/password entries here. username username password password url jdbc:mysql://localhost:3306/ADDRESS driverClassName com.mysql.jdbc.Driver Here is the web.xml file I am using in my WEB-INF directory. http://java.sun.com/dtd/web-app_2_3.dtd";> jdbc/address javax.sql.DataSource Container Rob - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problem connecting to mysql database with Tomcat and JNDI
Well, looking at your definition, I'm not seeing the following required element: Thanks, Scott Stewart [Manager, Software Development] [EMAIL PROTECTED] ClearSky Mobile Media, Inc. 56 E. Pine Street Suite 200 Orlando, FL 32801 USA -Original Message- From: Robert S. Jones [mailto:[EMAIL PROTECTED] Sent: Thursday, August 21, 2003 5:35 PM To: [EMAIL PROTECTED] Subject: Problem connecting to mysql database with Tomcat and JNDI Folks, I'm having trouble connecting to a mysql database through Tomcat. I'm using Tomcat 5.0.9a with mysql 4.0.14. I have the mysql 3.0.8 JDBC driver in ${TOMCAT_HOME}/common/lib. I'm running RedHat 8.0 with a stock kernel. I've been able to connect to the database without JNDI services. I believe I have the database user set up correctly. I have been all over the web trying to figure out what the problem is. It seems like everyone is having this problem, but no two solutions are the same. FWIW I've tried a lot of this on Tomcat 4 and have had the same results. I've traced the problem to the following code from the JSP file below: conn = ds.getConnection(); Any thoughts/ideas would be greatly appreciated. I'm at the end of my rope on this. Here is the error message I'm getting. java.lang.NullPointerException org.apache.jsp.usingDataSource_jsp._jspService(usingDataSource_jsp.java:74) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:3 20) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) Here is the JSP page I'm using: <[EMAIL PROTECTED] import="java.sql.*, javax.sql.*, javax.naming.*"%> Using a DataSource Using a DataSource <% DataSource ds = null; Connection conn = null; ResultSet result = null; Statement stmt = null; ResultSetMetaData rsmd = null; try { Context context = new InitialContext(); Context envCtx = (Context) context.lookup("java:comp/env"); ds = (DataSource)envCtx.lookup("jdbc/address"); if (ds != null) { conn = ds.getConnection(); stmt = conn.createStatement(); result = stmt.executeQuery("SELECT * FROM AddressList"); } } catch (SQLException e) { System.out.println("Error occurred " + e); } int columns = 0; try { rsmd = result.getMetaData(); // bad line columns = rsmd.getColumnCount(); } catch (SQLException e) { System.out.println("Error occurred " + e); } %> <% // write out the header cells containing the column labels try { for (int i = 1; i <= columns; i++) { out.write("" + rsmd.getColumnLabel(i) + ""); } %> <% // now write out one row for each entry in the database table while (result.next()) { out.write(""); for (int i = 1; i <= columns; i++) { out.write("" + result.getString(i) + ""); } out.write(""); } // close the connection, resultset, and the statement result.close(); stmt.close(); conn.close(); } // end of the try block catch (SQLException e) { System.out.println("Error " + e); } // ensure everything is closed finally { try { if (stmt != null) { stmt.close(); } } catch (SQLException e) {} try { if (conn != null) { conn.close(); } } catch (SQLException e ) {} } %> Here are the changes I made to my server.xml file. Of course, I've changed the username/password entries here. username username password password url jdbc:mysql://localhost:3306/ADDRESS driverClassName com.mysql.jdbc.Driver Here is the web.xml file I am using in my WEB-INF directory. http://java.sun.com/dtd/web-app_2_3.dtd";> jdbc/address javax.sql.DataSource Container Rob - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problem connecting to mysql database with Tomcat and JNDI
Ok, I tried that. Same results. Here is my new definition. username username password password url jdbc:mysql://localhost:3306/ADDRESS driverClassName com.mysql.jdbc.Driver Thanks, Rob On Fri, 2003-08-22 at 07:09, Scott Stewart wrote: > Well, looking at your definition, I'm not seeing the following > required element: > >auth="Container" > type="javax.sql.DataSource" /> > > Thanks, > > Scott Stewart > [Manager, Software Development] > [EMAIL PROTECTED] > > ClearSky Mobile Media, Inc. > 56 E. Pine Street Suite 200 > Orlando, FL 32801 > USA > > > > > > -Original Message- > From: Robert S. Jones [mailto:[EMAIL PROTECTED] > Sent: Thursday, August 21, 2003 5:35 PM > To: [EMAIL PROTECTED] > Subject: Problem connecting to mysql database with Tomcat and JNDI > > > Folks, > > I'm having trouble connecting to a mysql database through Tomcat. I'm > using Tomcat 5.0.9a with mysql 4.0.14. I have the mysql 3.0.8 JDBC > driver in ${TOMCAT_HOME}/common/lib. I'm running RedHat 8.0 with a > stock kernel. > > I've been able to connect to the database without JNDI services. I > believe I have the database user set up correctly. I have been all over > the web trying to figure out what the problem is. It seems like > everyone is having this problem, but no two solutions are the same. > > FWIW I've tried a lot of this on Tomcat 4 and have had the same results. > > I've traced the problem to the following code from the JSP file below: > > conn = ds.getConnection(); > > Any thoughts/ideas would be greatly appreciated. I'm at the end of my > rope on this. > > Here is the error message I'm getting. > > java.lang.NullPointerException > org.apache.jsp.usingDataSource_jsp._jspService(usingDataSource_jsp.java:74) > org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136) > javax.servlet.http.HttpServlet.service(HttpServlet.java:856) > org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:3 > 20) > org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293) > org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240) > javax.servlet.http.HttpServlet.service(HttpServlet.java:856) > > Here is the JSP page I'm using: > > <[EMAIL PROTECTED] import="java.sql.*, javax.sql.*, javax.naming.*"%> > > > Using a DataSource > > > Using a DataSource > <% > DataSource ds = null; > Connection conn = null; > ResultSet result = null; > Statement stmt = null; > ResultSetMetaData rsmd = null; > > try { > Context context = new InitialContext(); > Context envCtx = (Context) context.lookup("java:comp/env"); > ds = (DataSource)envCtx.lookup("jdbc/address"); > if (ds != null) { > conn = ds.getConnection(); > stmt = conn.createStatement(); > result = stmt.executeQuery("SELECT * FROM AddressList"); > } > } > catch (SQLException e) { > System.out.println("Error occurred " + e); > } > int columns = 0; > try { > rsmd = result.getMetaData(); // bad line > columns = rsmd.getColumnCount(); > } > catch (SQLException e) { > System.out.println("Error occurred " + e); > } > %> > > > <% // write out the header cells containing the column labels > try { > for (int i = 1; i <= columns; i++) { > out.write("" + rsmd.getColumnLabel(i) + ""); > } > %> > > <% // now write out one row for each entry in the database table > while (result.next()) { > out.write(""); > for (int i = 1; i <= columns; i++) { > out.write("" + result.getString(i) + ""); > } > out.write(""); > } > > // close the connection, resultset, and the statement > result.close(); > stmt.close(); > conn.close(); > } // end of the try block > catch (SQLException e) { > System.out.println("Error " + e); > } > // ensure everything is closed > finally { > try { > if (stmt != null) { > stmt.close(); > } > } catch (SQLException e) {} > try { > if (conn != null) { > conn.close(); > } > } catch (SQLException e ) {} > } > %> > > > > > &
RE: Problem connecting to mysql database with Tomcat and JNDI
Well Folks, the law of, "the longer a problem takes to resolve, the dumber the mistake" has held true once again. It turns out that I had my definition in the wrong place in the server.xml file. I'm aggravated, but glad to have the problem solved. Thanks Scott for your suggestions. I should have posted the whole server.xml file. That probably would have made the problem obvious to folks more experienced than me. Rob On Fri, 2003-08-22 at 09:00, Robert S. Jones wrote: > Ok, I tried that. Same results. Here is my new definition. > > >type="javax.sql.DataSource"/> > > > username > username > > > password > password > > > url > jdbc:mysql://localhost:3306/ADDRESS > > > driverClassName > com.mysql.jdbc.Driver > > > > > Thanks, > Rob > > > On Fri, 2003-08-22 at 07:09, Scott Stewart wrote: > > Well, looking at your definition, I'm not seeing the following > > required element: > > > > > auth="Container" > > type="javax.sql.DataSource" /> > > > > Thanks, > > > > Scott Stewart > > [Manager, Software Development] > > [EMAIL PROTECTED] > > > > ClearSky Mobile Media, Inc. > > 56 E. Pine Street Suite 200 > > Orlando, FL 32801 > > USA > > > > > > > > > > > > -Original Message- > > From: Robert S. Jones [mailto:[EMAIL PROTECTED] > > Sent: Thursday, August 21, 2003 5:35 PM > > To: [EMAIL PROTECTED] > > Subject: Problem connecting to mysql database with Tomcat and JNDI > > > > > > Folks, > > > > I'm having trouble connecting to a mysql database through Tomcat. I'm > > using Tomcat 5.0.9a with mysql 4.0.14. I have the mysql 3.0.8 JDBC > > driver in ${TOMCAT_HOME}/common/lib. I'm running RedHat 8.0 with a > > stock kernel. > > > > I've been able to connect to the database without JNDI services. I > > believe I have the database user set up correctly. I have been all over > > the web trying to figure out what the problem is. It seems like > > everyone is having this problem, but no two solutions are the same. > > > > FWIW I've tried a lot of this on Tomcat 4 and have had the same results. > > > > I've traced the problem to the following code from the JSP file below: > > > > conn = ds.getConnection(); > > > > Any thoughts/ideas would be greatly appreciated. I'm at the end of my > > rope on this. > > > > Here is the error message I'm getting. > > > > java.lang.NullPointerException > > org.apache.jsp.usingDataSource_jsp._jspService(usingDataSource_jsp.java:74) > > org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136) > > javax.servlet.http.HttpServlet.service(HttpServlet.java:856) > > org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:3 > > 20) > > org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293) > > org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240) > > javax.servlet.http.HttpServlet.service(HttpServlet.java:856) > > > > Here is the JSP page I'm using: > > > > <[EMAIL PROTECTED] import="java.sql.*, javax.sql.*, javax.naming.*"%> > > > > > > Using a DataSource > > > > > > Using a DataSource > > <% > > DataSource ds = null; > > Connection conn = null; > > ResultSet result = null; > > Statement stmt = null; > > ResultSetMetaData rsmd = null; > > > > try { > > Context context = new InitialContext(); > > Context envCtx = (Context) context.lookup("java:comp/env"); > > ds = (DataSource)envCtx.lookup("jdbc/address"); > > if (ds != null) { > > conn = ds.getConnection(); > > stmt = conn.createStatement(); > > result = stmt.executeQuery("SELECT * FROM AddressList"); > > } > > } > > catch (SQLException e) { > > System.out.println("Error occurred " + e); > > } > > int columns = 0; > > try { > > rsmd = result.getMetaData(); // bad line > > columns = rsmd.getColumnCount(); > > } > > catch (SQLException e) { > > System.out.println("Error occurred " + e); > > } > > %> > > > > > > <% // write out the header cells containing the column labels &g