Re: database application
Brantley Hobbs wrote: Cue Charles Caldarale hammering someone for not providing a Tomcat version in 3...2...1... Actually, I think he may have missed this one as he was hammering someone else for using a packaged Tomcat instead of the official distribution. ;-) 3..2..1.. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: database application
LOL Absolutely no problem. Someone has to do it! B. Caldarale, Charles R wrote: From: Brantley Hobbs [mailto:[EMAIL PROTECTED] Subject: Re: database application Cue Charles Caldarale hammering someone for not providing a Tomcat version in 3...2...1... (Sorry I'm late, our marvelous corporate e-mail server didn't let the original message through.) Being precise is one of the things they taught us in Engineering at the real school 70 odd miles west of you... (Can't resist getting a dig in when a bulldog speaks :-) Seriously, Eleonora...You should read here: http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html If she's using 5.5, then the config given is sadly out of date and conflicts with best practice (Logger elements, Context elements in server.xml, etc.). If it's a 5.0 version, then it's not supported, so moving up would be in order. What's even worse is the installation directory looks like one used by 3rd-party repackaged Tomcat versions, so getting it to work may be impossible. Installing a real Tomcat from http://tomcat.apache.org should probably be the first order of business. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: database application
Ok... I'm assuming you are using tomcat 5.0.x given they way you configured your datasource. If this isn't true, you might want to get a copy of the tomcat-docs webapp for your particular version of tomcat. The way JDBC connections are configured changed with tomcat 5.5.x and 6.0.x. Typically the error you are getting is the result of a mismatch between different parts of the config where the JNDI name is mentioned. I don't see that in what you posted though so it's an interesting problem. - What URL did you use to get the error? - Did you place the mysql driver in tomcat's common/lib folder (and ONLY in tomcat's common/lib folder)? That's required - Are there any related messages in the log files? - Is this an original package tomcat from tomcat.apache.org or some third party package? If a third party package, you might want to ask on a forum for your distribution. --David [EMAIL PROTECTED] wrote: Hi, Please help me. I use this introduction: http://localhost:8180/tomcat-docs/jndi-datasource-examples-howto.html database: mysql A simple java application works (see PS) [EMAIL PROTECTED]:/mnt/hda3/tyuk/dtest/java/database# java DbTableShow2 +---+---+---+ | id| foo | bar | +---+---+---+ | 1 | hello | 12345 | | 2 | hellox| 123456| +---+---+---+ However the tomcat application fails: -- description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Unable to get connection, DataSource invalid: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846) org.apache.jasper.runtime.PageContextImpl.access$11(PageContextImpl.java:784) org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:766) java.security.AccessController.doPrivileged(Native Method) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:764) org.apache.jsp.jsp.test_jsp._jspService(test_jsp.java:81) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:243) java.security.AccessController.doPrivileged(Native Method) javax.security.auth.Subject.doAsPrivileged(Subject.java:517) org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:272) org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161) --- Here my configuration file (/etc/tomcat5/server.xml: !-- Server Configuration File for Tomcat 5 on Debian You can find a more complete example in /usr/share/doc/tomcat5/examples/ -- !-- Note that component elements are nested corresponding to their parent-child relationships with each other -- !-- A Server is a singleton element that represents the entire JVM, which may contain one or more Service instances. The Server listens for a shutdown command on the indicated port. Note: A Server is not itself a Container, so you may not define subcomponents such as Valves or Loggers at this level. -- Server port=8005 shutdown=SHUTDOWN debug=0 Listener className=org.apache.catalina.mbeans.ServerLifecycleListener debug=0/ Listener className=org.apache.catalina.mbeans.GlobalResourcesLifecycleListener debug=0/ !-- Global JNDI resources -- GlobalNamingResources !-- Test entry for demonstration purposes -- Environment name=simpleValue type=java.lang.Integer value=30/ !-- Editable user database that can also be used by UserDatabaseRealm to authenticate users -- Resource name=UserDatabase auth=Container type=org.apache.catalina.UserDatabase description=User database that can be updated and saved /Resource ResourceParams name=UserDatabase parameter namefactory/name
Re: database application
Cue Charles Caldarale hammering someone for not providing a Tomcat version in 3...2...1... Seriously, Eleonora...You should read here: http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html Note particularly: *Please note that JNDI resource configuration has changed somewhat between Tomcat 5.0.x and Tomcat 5.5.x.* You will most likely need to modify your JNDI resource configurations to match the syntax in the example below in order to make them work in Tomcat 5.5.x. Brantley - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: database application
From: Brantley Hobbs [mailto:[EMAIL PROTECTED] Subject: Re: database application Cue Charles Caldarale hammering someone for not providing a Tomcat version in 3...2...1... (Sorry I'm late, our marvelous corporate e-mail server didn't let the original message through.) Being precise is one of the things they taught us in Engineering at the real school 70 odd miles west of you... (Can't resist getting a dig in when a bulldog speaks :-) Seriously, Eleonora...You should read here: http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html If she's using 5.5, then the config given is sadly out of date and conflicts with best practice (Logger elements, Context elements in server.xml, etc.). If it's a 5.0 version, then it's not supported, so moving up would be in order. What's even worse is the installation directory looks like one used by 3rd-party repackaged Tomcat versions, so getting it to work may be impossible. Installing a real Tomcat from http://tomcat.apache.org should probably be the first order of business. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: database application
This is a quick reiteration of key points found in the link below.. make sure you provide the GRANT for insert/select/update to the user you will be using e.g. mysql GRANT ALL PRIVILEGES ON *.* TO [EMAIL PROTECTED] - IDENTIFIED BY 'javadude' WITH GRANT OPTION; mysql create database javatest; mysql use javatest; mysql create table testdata ( - id int not null auto_increment primary key, - foo varchar(25), - bar int); JDBC access... I assume you have these resource statements either in applicationContext.xml or server.xml Resource name=jdbc/TestDB auth=Container type=javax.sql.DataSource/ ResourceParams name=jdbc/TestDB parameter namefactory/name valueorg.apache.commons.dbcp.BasicDataSourceFactory/value /parameter !-- Maximum number of dB connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to 0 for no limit. -- parameter namemaxActive/name value100/value /parameter !-- Maximum number of idle dB connections to retain in pool. Set to 0 for no limit. -- parameter namemaxIdle/name value30/value /parameter !-- Maximum time to wait for a dB connection to become available in ms, in this example 10 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. -- parameter namemaxWait/name value1/value /parameter !-- MySQL dB username and password for dB connections -- parameter nameusername/name valuejavauser/value /parameter parameter namepassword/name valuejavadude/value /parameter !-- Class name for mm.mysql JDBC driver -- parameter namedriverClassName/name valueorg.gjt.mm.mysql.Driver/value /parameter !-- The JDBC connection url for connecting to your MySQL dB. The autoReconnect=true argument to the url makes sure that the mm.mysql JDBC Driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours. -- parameter nameurl/name valuejdbc:mysql://localhost:3306/javatest?autoReconnect=true/value /parameter /ResourceParams /Context lets not forget web.xml ?xml version=1.0 encoding=ISO-8859-1? !DOCTYPE web-app PUBLIC -//Sun Microsystems, Inc.//DTD Web Application 2.3//EN http://java.sun.com/dtd/web-app_2_3.dtd; web-app descriptionMySQL Test App/description resource-ref descriptionDB Connection/description res-ref-namejdbc/TestDB/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref /web-app Now finally using the JDBC reference in the java class Context ctx = new InitialContext(); if(ctx == null ) throw new Exception(Boom - No Context); DataSource ds = (DataSource)ctx.lookup( java:comp/env/jdbc/TestDB); InitialContext initCtx = new InitialContext(); DataSource ds = (DataSource) initCtx.lookup(java:comp/env/my-datasource); Connection conn = ds.getConnection(); JNDI access: ApplicationContext.xml or server.xml first the prelim ConnectionPool params Environment name=tyrexDomainConfig type=java.lang.String value=domain-config.xml/ Environment name=tyrexDomainName type=java.lang.String value=myDomain/ Then in the same file the myDataSource Resource name=my-datasource auth=Container type=tyrex.resource.Resource/ ResourceParams name=my-datasource parameter namename/name valuemyDataSource/value /parameter /ResourceParamsand in $TOMCAT_HOME/conf/catalina.policy allow JNDI access to the described resource permission org.apache.naming.JndiPermission jndi://comp.env/my-datasource; Now the test in java via my-datasource InitialContext initCtx = new InitialContext(); DataSource ds = (DataSource) initCtx.lookup(jndi:comp/env/my-datasource); Connection conn = ds.getConnection(); More information on configuration and deployment to MySQL DB available at http://tomcat.apache.org/tomcat-4.1-doc/jndi-datasource-examples-howto.html HTH Martin __ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. Date: Wed, 13 Aug 2008 22:38:32 +0200 From: [EMAIL PROTECTED] Subject: database application To: users@tomcat.apache.org Hi, Please help me. I use this introduction: http://localhost:8180/tomcat-docs/jndi-datasource-examples-howto.html