RE: Error while connecting to MySQL database
Hi, I don't' know whether specifying db.properties works or not, but I configured a datasource for mysql as follows: 1. Shutdown tomcat. 2. Enter followin in TOMCAT_HOME/conf/server.xml (If you have an entry in server.xml for this update it as below) Resource name=jdbc/MyDB type=javax.sql.DataSource driverClassName=org.gjt.mm.mysql.Driver factory=org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory maxActive=10 maxIdle=1 maxWait=5000 minIdle=1 initialSize=10 validationQuery=select 1 username=root password= url=jdbc:mysql://localhost/testdb / 3. Enter following in your-web-app/META-INF/context.xml file ResourceLink debug=5 name=jdbc/MyDB global=jdbc/MyDB type=javax.sql.DataSource/ 4. Enter in your-web-app/WEB-INF/web.xml following resource-ref res-ref-namejdbc/MyDB/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref 5. Then in you code use the JNDI lookup to get the datasourec and connetion as useual. Regards, Jitendra -Original Message- From: navaneethan loganathan [mailto:[EMAIL PROTECTED] Sent: Thursday, June 29, 2006 5:27 AM To: users@tomcat.apache.org Subject: Error while connecting to MySQL database Hi, I am facing a problem with my Apache-Tomcat-MySQL installation.MyEnvironment is as follows: Redhat ES4(2.6.9-5.EL), Apache-Tomcat-5.5.15, MySQL 4.1.12, Java version 1.5.0_06, Apache-Tomcat connector ajp13, mysql-connector-java-3.2.0-alpha-bin.jar. After installation and configuration I am unable to connect to the database through the application and getting the following exception in catalina.outlog file. java.lang.NullPointerException at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:164) However, I am able to browse my site perfectly with http://localhost/index.jsp (the connector also configured perfectly, so that I do not need to specify the port number in URL). I put the mysql-connector-java-3.2.0-alpha-bin.jar file in $CATALINA_HOME/common/lib and also specified in CLASSPATH. I am able to login to MySQL through command and access the database without any problem. My db.properties is as under: # MySQL database access properties db.driver = org.gjt.mm.mysql.Driver db.url = jdbc:mysql://localhost:3306/testdb db.user = root db.pwd = Any clue will be very much helpfull.Thanks in advance. - 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: Tomcat 5.5 JNDI Question Using Admin
Hi Scott, I had also this problem some time back. You need to create a file named context.xml in WEB-APP/META-INF directory. The resource needs to be defined her as follows ?xml version=1.0 encoding=UTF-8? Context Resource name=jdbc/BuilderDB type= password=admin driverClassName=com.mysql.jdbc.Driver factory= maxIdle=2 maxWait=5000 validationQuery=select * from test username=root url=jdbc:mysql://localhost/builder maxActive=4/ /Context Note in the above that the value of attribute 'type' should be the DataSource class from your db driver jar. Also you need to define the attribute 'factory' which is the impl class from your db driver jar implementating javax.sql.ConnectionPoolDataSource. Please check that the url is correct. I think you need to specify the port along with localhost. Regards, Jitendra -Original Message- From: Scott Purcell [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 28, 2006 7:03 PM To: users@tomcat.apache.org Subject: Tomcat 5.5 JNDI Question Using Admin Hello, I am receiving errors when configuring a JNDI resource for my database using Tomcat 5.5 on a Windoz box. I used the admin interface and entered the following data: in admin screen under Data Sources JNDI Name= jdbc/BuilderDB Driver com.mysql.jdbc.Driver Data Source URL=jdbc:mysql://localhost/builder JDBC Driver Class=com.mysql.jdbc.Driver Then I made sure my driver was in common/lib/mysql-connector-java-3.1.12 Then went to the web.xml file added my resource web.xml resource-ref descriptionDB Connection/description res-ref-namejdbc/BuilderDB/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref After committing the change in the admin module, it updated the server.xml and added this the Resource (see below). When I try and get a jndi connection doing a lookup, I get this error (see below). As I read the docs for 5.5, and I do not see any examples. Does anyone see any problems with this, or know what may cause this error? Thanks, Scott error org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSo urce.java:780) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSourc e.java:540) at foo.DBTest.init(DBTest.java:23) at org.apache.jsp.test_jsp._jspService(test_jsp.java:51) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja va:332) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:173) at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter. java:142) Server.xml ?xml version=1.0 encoding=UTF-8? Server Listener className=org.apache.catalina.core.AprLifecycleListener/ Listener className=org.apache.catalina.mbeans.GlobalResourcesLifecycleListener/ Listener className=org.apache.catalina.storeconfig.StoreConfigLifecycleListener / Listener className=org.apache.catalina.mbeans.ServerLifecycleListener/ GlobalNamingResources Environment name=simpleValue type=java.lang.Integer value=30/ Resource auth=Container description=User database that can be updated and saved name=UserDatabase type=org.apache.catalina.UserDatabase pathname=conf/tomcat-users.xml factory=org.apache.catalina.users.MemoryUserDatabaseFactory/ Resource name=jdbc/BuilderDB type=javax.sql.DataSource password=admin driverClassName=com.mysql.jdbc.Driver maxIdle=2 maxWait=5000 validationQuery=select * from test username=root url=jdbc:mysql://localhost/builder maxActive=4/ /GlobalNamingResources Service name=Catalina Connector port=8080 redirectPort=8443 minSpareThreads=25 connectionTimeout=2 maxThreads=150 maxSpareThreads=75 /Connector Connector port=8009 redirectPort=8443 protocol=AJP/1.3 /Connector Engine defaultHost=localhost name=Catalina Realm className=org.apache.catalina.realm.UserDatabaseRealm/ Host appBase=webapps name=localhost /Host /Engine /Service /Server - To start a new topic, e-mail:
Using Datasource for cloudscape
Contents of file CATALINA_HOME/webapps/myApp/META-INF/context.xml ?xml version=1.0 encoding=UTF-8? Context Resource auth=Container name=jdbc/MyDB type=com.ibm.db2j.jdbc.DB2jDataSource password=password driverClassName=com.ibm.db2j.jdbc.DB2jDriver factory=com.ibm.db2j.jdbc.DB2jConnectionPoolDataSource maxIdle=4 testOnBorrow=true validationQuery=select 1 username=user url=jdbc:db2j:E:/apache-tomcat-5.5.17/webapps/datasourcedemo/SampleDB timeBetweenEvictionRunsMillis=3 maxActive=8/ /Context Regards, Jitendra Kharche - 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] - 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: Using Datasource for cloudscape
Contents of file CATALINA_HOME/webapps/myApp/META-INF/context.xml ?xml version=1.0 encoding=UTF-8? Context Resource auth=Container name=jdbc/MyDB type=com.ibm.db2j.jdbc.DB2jDataSource password=password driverClassName=com.ibm.db2j.jdbc.DB2jDriver factory=com.ibm.db2j.jdbc.DB2jConnectionPoolDataSource maxIdle=4 testOnBorrow=true validationQuery=select 1 username=user url=jdbc:db2j:E:/apache-tomcat-5.5.17/webapps/datasourcedemo/SampleDB timeBetweenEvictionRunsMillis=3 maxActive=8/ /Context Regards, Jitendra Kharche - 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] - 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: Using Datasource for cloudscape
Hi Dilan, Have you got all the details about my problem. Regards, Jitendra Kharche -Original Message- From: Jitendra Kharche [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 21, 2006 4:09 PM To: Tomcat Users List Subject: RE: Using Datasource for cloudscape Hi Dilan, Thanks for helping again. I had attached files but it seems attachments are not allowed. I am adding the contets of these files below. To keep the mail size samll I am removing old contents of the mail. For the sake of clarity I am putting my problem statement also. Problem: I am using Tomcat 5.5.17 and tried running a sample datasource application having a jsp page (see contents below) using the Cloudscape database. I have added the driver jar into CATALINA_HOME/common/lib directory. When I run the jsp I get following exception WARNING: Unexpected exception resolving reference java.lang.NoSuchMethodException: com.ibm.db2j.jdbc.DB2jDataSource.setScope(boolean) at java.lang.Class.getMethod(Class.java:1581) at com.ibm.db2j.jdbc.DB2jAbstractDataSource.getObjectInstance(Unknown Source) Contents of file CATALINA_HOME/webapps/myApp/dbdemo.jsp %@ page import=javax.sql.* % %@ page import=java.sql.* % %@ page import=javax.naming.* % % Connection con = null; Statement stmt = null; try { Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup(java:comp/env); DataSource ds = (DataSource)envContext.lookup(jdbc/MyDB); System.out.println(Got DataSource\n); con = ds.getConnection(); System.out.println(Got Connection\n); } catch(java.lang.Exception e) { e.printStackTrace(); System.err.print(e.getClass().getName()); System.err.println(e.getMessage()); } try { stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(SELECT * FROM employee); System.out.println(Table assignment after insertion:); % Your table contains the following entries:BR table trBthemp_id/ththemp_name/ththemp_dept/th/B/tr % while (rs.next()) { String emp_id = rs.getString(emp_id); String emp_name = rs.getString(emp_name); String emp_dept = rs.getString(emp_dept); % tr td%=emp_id%/tdtd%=emp_name%/tdtd%=emp_dept%/td /tr /table % } rs.close(); stmt.close(); con.close(); } catch(java.lang.Exception e) { e.printStackTrace(); }% Contents of file CATALINA_HOME/conf/server.xml ?xml version=1.0 encoding=UTF-8? Server Listener className=org.apache.catalina.core.AprLifecycleListener/ Listener className=org.apache.catalina.mbeans.GlobalResourcesLifecycleListener/ Listener className=org.apache.catalina.storeconfig.StoreConfigLifecycleListener / Listener className=org.apache.catalina.mbeans.ServerLifecycleListener/ GlobalNamingResources Environment name=simpleValue type=java.lang.Integer value=30/ Resource auth=Container description=User database that can be updated and saved name=UserDatabase type=org.apache.catalina.UserDatabase pathname=conf/tomcat-users.xml factory=org.apache.catalina.users.MemoryUserDatabaseFactory/ Resource name=jdbc/MyDB type=javax.sql.DataSource password=password driverClassName=com.ibm.db2j.jdbc.DB2jDriver maxIdle=2 maxWait=5000 username=user url=jdbc:db2j:E:/apache-tomcat-5.5.17/webapps/datasourcedemo/SampleDB maxActive=4/ /GlobalNamingResources Service name=Catalina Connector port=8080 redirectPort=8443 minSpareThreads=25 connectionTimeout=2 maxSpareThreads=75 maxThreads=150 /Connector Connector port=8009 redirectPort=8443 protocol=AJP/1.3 /Connector Engine defaultHost=localhost name=Catalina Realm className=org.apache.catalina.realm.UserDatabaseRealm/ Host appBase=webapps name=localhost /Host /Engine /Service /Server Contents of file CATALINA_HOME/webapps/myApp/WEB-INF/web.xml ?xml version=1.0 encoding=UTF-8? web-app id=WebApp_ID version=2.4 xmlns=http://java.sun.com/xml/ns/j2ee; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; xsi:schemaLocation=http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd; display-name datasourcedemo/display-name welcome-file-list welcome-fileindex.html/welcome-file welcome-fileindex.htm
Tomcat 5.5 and DataSource
Hi, Can anybody help me to get a working copy of a simple database application (using DataSource) in Tomcat 5.5? Desperately looking for your help. Regards, Jitendra Kharche - 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: Using Datasource for cloudscape
res-ref-namejdbc/MyDB/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref /web-app Contents of file CATALINA_HOME/webapps/myApp/META-INF/context.xml ?xml version=1.0 encoding=UTF-8? Context Resource auth=Container name=jdbc/MyDB type=com.ibm.db2j.jdbc.DB2jDataSource password=password driverClassName=com.ibm.db2j.jdbc.DB2jDriver factory=com.ibm.db2j.jdbc.DB2jConnectionPoolDataSource maxIdle=4 testOnBorrow=true validationQuery=select 1 username=user url=jdbc:db2j:E:/apache-tomcat-5.5.17/webapps/datasourcedemo/SampleDB timeBetweenEvictionRunsMillis=3 maxActive=8/ /Context Regards, Jitendra Kharche - 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: Using Datasource for cloudscape
Hi Dilan, Thanks for helping. Attaching the files CATALINA_HOME/conf/server.xml CATALINA_HOME/webapps/myApp/WEB-INF/web.xml CATALINA_HOME/webapps/myApp/META-INF/context.xml The context.xml is placed in CATALINA_HOME/webapps/myApp/META-INF. There are no additional config files for database or resources. Please ask any additional info required. Regards, Jitendra Kharche Geometric Software Solutions Co. Ltd. Work: +91-20-2290 6351 This e-mail communication and any attachments are privileged and confidential and intended only for the use of the recipients named above. If you are not the intended recipient, please do not review, disclose, disseminate, distribute or copy this e-mail and attachments. If you have received this communication in error, please notify the sender immediately by email or telephone at+91-20-22906351. * -Original Message- From: Dilan Kelanibandara [mailto:[EMAIL PROTECTED] Sent: Monday, June 19, 2006 8:58 PM To: 'Tomcat Users List' Subject: RE: Using Datasource for cloudscape Hi Jitendra, To claryfiy your error please send followings in your configuration (as an attachment or copy ,paste here) CATALINA_HOME/conf/server.xml CATALINA_HOME/webapps/yourApp/WEB-INF/web.xml context.xml Where do you have defined your context.xml? And any other additional configuration files you have for database configuration and resource references Regards, Dilan -Original Message- From: Jitendra Kharche [mailto:[EMAIL PROTECTED] Sent: Monday, June 19, 2006 6:20 PM To: Tomcat Users List Subject: RE: Using Datasource for cloudscape Hi Dilan, Please see my next mail. In which I have modified the context.xml and got following error WARNING: Unexpected exception resolving reference java.lang.NoSuchMethodException: com.ibm.db2j.jdbc.DB2jDataSource.setScope(boolean) at java.lang.Class.getMethod(Class.java:1581) at com.ibm.db2j.jdbc.DB2jAbstractDataSource.getObjectInstance(Unknown Source) Then I added the resourec-ref entry in web.xml, but I still get the same error. Regards, Jitendra Kharche Geometric Software Solutions Co. Ltd. Work: +91-20-2290 6351 This e-mail communication and any attachments are privileged and confidential and intended only for the use of the recipients named above. If you are not the intended recipient, please do not review, disclose, disseminate, distribute or copy this e-mail and attachments. If you have received this communication in error, please notify the sender immediately by email or telephone at+91-20-22906351. * -Original Message- From: Dilan Kelanibandara [mailto:[EMAIL PROTECTED] Sent: Monday, June 19, 2006 8:34 PM To: 'Tomcat Users List' Subject: RE: Using Datasource for cloudscape Hi Jitenra, Tomcat5.5 uses a defferent way of defining JNDI resources. That is why you get this error. It seems your resource declaration at web.xml is missing. Please stick to tomcat documentation here http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html where you have to define context.xml in CATALINA_HOME/webapps/yourApp/META-INF/ you have to define database connectivity in CATALINA_HOME/conf/server.xml as usual, where tomcat has commented all the sample database connectivities. Uncomment your required one their and define them web.xml should have resource declaration at bottom if web.xml file (this is normally, but where you declare in web.xml depends on your other resource declaration at web.xml) That is all you have to do. Please stick to tomcat documentation. Regards, Dilan Kelanibandara -Original Message- From: Jitendra Kharche [mailto:[EMAIL PROTECTED] Sent: Monday, June 19, 2006 5:28 PM To: Tomcat Users List Subject: Using Datasource for cloudscape Hi All, I am using Tomcat 5.5.17 and tried running a sample datasource application using the Cloudscape database. I have added the driver jar into common/lib directory. The context.xml has following configuration for datasource Resource auth=Container name=jdbc/MyDB type=javax.sql.DataSource password=password driverClassName=com.ibm.db2j.jdbc.DB2jDriver maxIdle=4 testOnBorrow=true validationQuery=select 1 username=user url=jdbc:db2j:E:/apache-tomcat-5.5.17/webapps/datasourcedemo/SampleDB timeBetweenEvictionRunsMillis=3 maxActive=8/ I have created a datasource using the admin application and it added following entry in server.xml Resource name=jdbc/MyDB type=javax.sql.DataSource password=password driverClassName=com.ibm.db2j.jdbc.DB2jDriver maxIdle=2 maxWait=5000 username=user url=jdbc:db2j:E:/apache-tomcat-5.5.17/webapps/datasourcedemo/SampleDB maxActive=4/ The appliaction has a jsp page with following code