Re: Cannot connect to database using DataSource
Hi! For TC 5.5.x, put the name-value-pairs of all parameter elements inside the Resource start tag as attributes. Good luck! Am Mittwoch, den 14.09.2005, 16:30 +0800 schrieb Michael Lai: I have a MySQL database in which I created a database named, javatest, and I am using Tomcat 5.5.9. I have unable to connect my database using Java's DataSource method. Here is my ROOT.xml setup for my application context: Context path= docBase=/home/tomcat/applications/ debug=0 reloadable=true Resource name=jdbc/DBTest type=javax.sql.DataSource auth=Container / ResourceParams name=jdbc/DBTest parameter nameusername/name valuejavauser/value /parameter parameter namepassword/name valuejavadude/value /parameter parameter namedriverClassName/name valuecom.mysql.jdbc.Driver/value /parameter parameter nameurl/name valuejdbc:mysql://localhost/javatest?autoReconnect=true/value /parameter /ResourceParams /Context I created a simple servlet to test the database connection: public class TestSQL extends HttpServlet { private Connection conn = null; public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType(text/html); PrintWriter out = response.getWriter(); try { Context ctx = new InitialContext(); Context appContext = (Context)ctx.lookup(java:comp/env); DataSource ds = (DataSource)appContext.lookup(jdbc/DBTest); conn = ds.getConnection(); } catch (Exception e) { e.printStackTrace(); } if (conn != null) { out.println(Connection successful); } else { out.println(Unsuccessful); } } It prints out Unsuccessful. I also tried using the traditional DriverManager and that works. Here is my web.xml in case it is needed for analysis: ?xml version=1.0 encoding=ISO-8859-1? web-app version=2.4 uri=http://java.sun.com/xml/ns/j2ee; resource-ref res-ref-namejdbc/DBTest/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref servlet servlet-nameTestSQL/servlet-name servlet-classTestSQL/servlet-class /servlet servlet-mapping servlet-nameTestSQL/servlet-name url-pattern/servlet/TestSQL/url-pattern /servlet-mapping /web-app I would appreciate it very much if someone can have a look at this and tell me what I am doing wrong with the DataSource alternative. Michael. - 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: cannot connect a sqlserver
When you restore a backup using SQLServer, you must delete and re-add the database users for that database. It's deceiving, because when you restore the database, and look at the users in Enterprise Manager, they are still there and you have no problem querying the database using Query Analyzer. Try deleting the users, then adding them back and don't forget to re-run your permissions once you've added the users back. /robert -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, December 16, 2004 8:56 AM To: [EMAIL PROTECTED] Subject: cannot connect a sqlserver I have a problem building a testserver with a webapp using sqlserver2000. We got a productionserver running, so I installed java SDK (j2sdk-1_4_2_04-windows-i586-p.exe),tomcat (jakarta-tomcat-4.1.30.exe) and SQLserver2000 (restored a backup) and took the .war file from the productionserver and placed it under the webapps directory. I changed the .properties file started Tomcat again. Are ther more changes to do??? This is the SQLException I get: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid object name 'LogonUser'. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unkn own Source) at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(Delegatin gPreparedStatement.java:205) at com.quinity.standard.business.StdEntity.retrieve(StdEntity.java) at nl.terrafilius.lms.business.LogonUser.retrieveWithLogonData(LogonUser.java ) at nl.terrafilius.lms.servlet.HandlerLogon.handleActionLogon(HandlerLogon.jav a) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorIm pl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at com.quinity.standard.servlet.StdHandler.handle(StdHandler.java) at com.quinity.standard.servlet.StdHandler.handle(StdHandler.java) at com.quinity.standard.servlet.StdController.doPost(StdController.java) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicati onFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilter Chain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve. java:256) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.inv okeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480 ) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve. java:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.inv okeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480 ) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:1 80) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.inv okeNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValv e.java:171) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.inv okeNext(StandardPipeline.java:641) at
Re: Cannot connect to remote server
Which version of Java you are using. Tomcat 5.5 requires JDK 5. Or you need to download an extra package from jakarta. rgds Antony Paul On Wed, 20 Oct 2004 01:11:34 +1000, Robert Mark Bram [EMAIL PROTECTED] wrote: Hi All! I am using RH9 with Tomcat 5.5.3 I have installed Tomcat as a Daemon process according to these instructions: http://phd.netcomp.monash.edu.au/RobertMarkBram/protected/notes/installingTomcat5.txt I have $CATALINA_HOME/conf/server.xml set up so that Tomcat runs on port 8080. But when I access http://localhost:8080 I get Cannot connect to remote server. When I examine catalina.out log I find the following exception: 20/10/2004 00:32:51 org.apache.catalina.startup.Bootstrap initClassLoaders SEVERE: Class loader creation threw exception java.lang.NoClassDefFoundError: javax/management/MBeanServerFactory ... Further debugging information is below. Any ideas about what is going wrong would be most appreciated! Rob :) /usr/local/jakarta-tomcat-5.5.3/logs #host localhost Host localhost not found: 3(NXDOMAIN) /usr/local/jakarta-tomcat-5.5.3/logs #cat /etc/hosts # Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost localhost 127.0.0.1 localhost dijong /usr/local/jakarta-tomcat-5.5.3/logs #cat /etc/resolv.conf ; generated by /sbin/dhclient-script search @home nameserver 192.168.0.1 /usr/local/jakarta-tomcat-5.5.3/logs #tail -13 catalina.out 20/10/2004 00:32:51 org.apache.catalina.startup.Bootstrap initClassLoaders SEVERE: Class loader creation threw exception java.lang.NoClassDefFoundError: javax/management/MBeanServerFactory at org.apache.catalina.startup.Bootstrap.createClassLoader(Bootstrap.java:161) at org.apache.catalina.startup.Bootstrap.initClassLoaders(Bootstrap.java:97) at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:189) at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:257) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.daemon.support.DaemonLoader.load(DaemonLoader.java:201) jsvc.exec error: Service exit with a return value of 1 My /etc/rc.d/init.d/Tomcat5 is below. #!/bin/sh ## # # Copyright 2004 The Apache Software Foundation. # # Licensed under the Apache License, Version 2.0 (the License); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an AS IS BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ## # # Small shell script to show how to start/stop Tomcat using jsvc # If you want to have Tomcat running on port 80 please modify the server.xml # file: # #!-- Define a non-SSL HTTP/1.1 Connector on port 80 -- #Connector className=org.apache.catalina.connector.http.HttpConnector # port=80 minProcessors=5 maxProcessors=75 # enableLookups=true redirectPort=8443 # acceptCount=10 debug=0 connectionTimeout=6/ # # That is for Tomcat-5.0.x (Apache Tomcat/5.0) # # Adapt the following lines to your configuration JAVA_HOME=/usr/java/j2sdk1.4.2_02 CATALINA_HOME=/usr/local/jakarta-tomcat-5.5.3 DAEMON_HOME=/usr/local/jakarta-tomcat-5.5.3 TOMCAT_USER=robertmarkbram TMP_DIR=/var/tmp CATALINA_OPTS= CLASSPATH=\ $JAVA_HOME/lib/tools.jar:\ $CATALINA_HOME/bin/commons-daemon.jar:\ $CATALINA_HOME/bin/bootstrap.jar case $1 in start) # # Start Tomcat # $DAEMON_HOME/bin/jsvc \ -user $TOMCAT_USER \ -home $JAVA_HOME \ -Dcatalina.home=$CATALINA_HOME \ -Djava.io.tmpdir=$TMP_DIR \ -outfile $CATALINA_HOME/logs/catalina.out \ -errfile '1' \ $CATALINA_OPTS \ -cp $CLASSPATH \ org.apache.catalina.startup.Bootstrap # # To get a verbose JVM #-verbose \ # To get a debug of jsvc. #-debug \ ;; stop) # # Stop Tomcat # PID=`cat /var/run/jsvc.pid` kill $PID ;; *) echo Usage tomcat.sh start/stop exit 1;; esac -- Robert Mark Bram http://phd.netcomp.monash.edu.au/RobertMarkBram/default.asp B.Comp.(Systems Development/Business
RE: cannot connect
-Original Message- From: Brzezinski, Paul J [mailto:[EMAIL PROTECTED]] Sent: Monday, January 13, 2003 7:21 PM To: Tomcat Users List Subject: Re: cannot connect Faine, Mark wrote: Apache 2.0.43 mod_jk2 2.0.0 Tomcat 4.0.6 Can't get socket to work, I get this error message: Is this the log from apache or tomcat? It is my Apache log file [Mon Jan 13 14:43:21 2003] [notice] Apache/2.0.43 (Unix) mod_ssl/2.0.43 OpenSSL/0.9.6g DAV/2 mod_jk2/2.0.0 configured -- resuming normal operations [Mon Jan 13 14:43:39 2003] [error] channelUn.connect() connect failed 2 No such file or directory [Mon Jan 13 14:43:39 2003] [error] ajp13.connect() failed ajp13:/usr/local/tomcat/logs/jk2.socket [Mon Jan 13 14:43:39 2003] [error] ajp13.service() failed to connect endpoint errno=2 No such file or directory [Mon Jan 13 14:43:39 2003] [error] ajp13.service() Error forwarding ajp13:/usr/local/tomcat/logs/jk2.socket 1 1 [Mon Jan 13 14:43:39 2003] [error] mod_jk.handler() Error connecting to tomcat 12 Is the socket supposed to be created automatically on the fly? (upon starting of server) I believe so. When run tomcat does tomcat create/use the socket? I've had trouble in the past getting the channelUnix socket to work -- was related to the ClassLoaders not functioning properly on Solaris 8 (Apache 2.0.40, Tomcat 4.1.15, mod_jk2 2.0.1). Because Tomcat couldn't create the socket, Apache couldn't find it, so it couldn't use it. Do you have any more information on this. I need to either fix it or work-around it, I also need to determine if this is indeed the problem. Thanks, -Mark -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: cannot connect
: -Original Message- : From: Faine, Mark [mailto:[EMAIL PROTECTED]] : Sent: Tuesday, January 14, 2003 8:34 AM : To: 'Tomcat Users List' : Subject: RE: cannot connect : : : : : -Original Message- : From: Brzezinski, Paul J [mailto:[EMAIL PROTECTED]] : Sent: Monday, January 13, 2003 7:21 PM : To: Tomcat Users List : Subject: Re: cannot connect : : : Faine, Mark wrote: : : Apache 2.0.43 : mod_jk2 2.0.0 : Tomcat 4.0.6 : : Can't get socket to work, I get this error message: : : : Is this the log from apache or tomcat? : : : It is my Apache log file : : [Mon Jan 13 14:43:21 2003] [notice] Apache/2.0.43 (Unix) : mod_ssl/2.0.43 : OpenSSL/0.9.6g DAV/2 mod_jk2/2.0.0 configured -- resuming normal : operations [Mon Jan 13 14:43:39 2003] [error] channelUn.connect() : connect failed 2 No such file or directory [Mon Jan 13 : 14:43:39 2003] : [error] ajp13.connect() failed : ajp13:/usr/local/tomcat/logs/jk2.socket : [Mon Jan 13 14:43:39 2003] [error] ajp13.service() failed to connect : endpoint errno=2 No such file or directory : [Mon Jan 13 14:43:39 2003] [error] ajp13.service() Error forwarding : ajp13:/usr/local/tomcat/logs/jk2.socket 1 1 : [Mon Jan 13 14:43:39 2003] [error] mod_jk.handler() Error : connecting to : tomcat 12 : : Is the socket supposed to be created automatically on the fly? (upon : starting of server) : : : I believe so. When run tomcat does tomcat create/use the : socket? I've : had trouble in the past getting the channelUnix socket to work -- was : related to the ClassLoaders not functioning properly on Solaris 8 : (Apache 2.0.40, Tomcat 4.1.15, mod_jk2 2.0.1). Because : Tomcat couldn't : create the socket, Apache couldn't find it, so it couldn't use it. : : Do you have any more information on this. I need to either : fix it or work-around it, I also need to determine if this is : indeed the problem. Do you get any complaints from tomcat when you start it up manually (as opposed to configuring apache to start up or connect to an already running instance of tomcat)? Check $catalina_home/logs/catalina.out for messages about can't create apr... Unfortunately, I don't have copies of the messages available -- it's back from mid-November or late November time-frame if you want to search the archives... http:[EMAIL PROTECTED]/ If you search the archive, you may find that searching for my last name may bring up the messages, I posted a few to the developer list and got some responses from one or two of the developers re: this problem. One of the things I do remember, one of the developers told me that I could work-around this problem until the ClassLoader problem is permanently resolved by moving all the jar files in $catalina_home/server/lib to $catalina_home/common/lib. I was told that this totally defeats the purpose of the ClassLoader hierarchy. Your mileage may vary. These are the files I moved from $catalina_home/server/lib to $catalina_home/common/lib, once I did this, I no longer received error messages in $catalina_home/logs/catalina.out regarding the apr/channelUnix file problem: catalina-ant.jar catalina.jar commons-beanutils.jar commons-digester.jar commons-logging.jar commons-modeler.jar jakarta-regexp-1.2.jar mx4j-jmx.jar servlets-cgi.jar servlets-common.jar servlets-default.jar servlets-invoker.jar servlets-manager.jar servlets-ssi.jar servlets-webdav.jar tomcat-coyote.jar tomcat-http11.jar tomcat-jk.jar tomcat-jk2.jar tomcat-util.jar tomcat-warp.jar : Thanks, : -Mark : : -- : To unsubscribe, e-mail: : mailto:tomcat-user-: [EMAIL PROTECTED] : For : additional commands, : e-mail: mailto:[EMAIL PROTECTED] : -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: cannot connect
Faine, Mark wrote: Apache 2.0.43 mod_jk2 2.0.0 Tomcat 4.0.6 Can't get socket to work, I get this error message: Is this the log from apache or tomcat? [Mon Jan 13 14:43:21 2003] [notice] Apache/2.0.43 (Unix) mod_ssl/2.0.43 OpenSSL/0.9.6g DAV/2 mod_jk2/2.0.0 configured -- resuming normal operations [Mon Jan 13 14:43:39 2003] [error] channelUn.connect() connect failed 2 No such file or directory [Mon Jan 13 14:43:39 2003] [error] ajp13.connect() failed ajp13:/usr/local/tomcat/logs/jk2.socket [Mon Jan 13 14:43:39 2003] [error] ajp13.service() failed to connect endpoint errno=2 No such file or directory [Mon Jan 13 14:43:39 2003] [error] ajp13.service() Error forwarding ajp13:/usr/local/tomcat/logs/jk2.socket 1 1 [Mon Jan 13 14:43:39 2003] [error] mod_jk.handler() Error connecting to tomcat 12 Is the socket supposed to be created automatically on the fly? (upon starting of server) I believe so. When run tomcat does tomcat create/use the socket? I've had trouble in the past getting the channelUnix socket to work -- was related to the ClassLoaders not functioning properly on Solaris 8 (Apache 2.0.40, Tomcat 4.1.15, mod_jk2 2.0.1). Because Tomcat couldn't create the socket, Apache couldn't find it, so it couldn't use it. My workers2.properties file and jk2.properties files are almost exact copies of the common examples. I can post them anyway if it will help. Also, Could ports blocked by the firewall cause any problems with tomcat/apache integration and normal operation? Any suggestions would be appreciated Thanks, Mark -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Cannot connect Servlet/JSP running in Tomcat to MySQL Database
Is your Tomcat using the security manager?? That would explain the error message. If so, you'll have to allow access to the datasource in catalina.policy. Otherwise it should work. --David On Wednesday 05 December 2001 05:19 pm, you wrote: Hi, I am unable to connect a servlet or jsp running in Tomcat to a MySQL database. Here are the particulars: Tomcat Version: 4.0.1 MySQL Version: 3.23.45 MySQL JDBC Driver Version: mm.mysql-2.0.4-bin.jar Linux Version: Red Hat 7.1 running Kernel Version 2.4.2-2smp Here is some sample code: *** * *** %@ page import=java.sql.* % %! Connection c; % % try { Class.forName(org.gjt.mm.mysql.Driver).newInstance(); } catch (Exception e) {} try { c = DriverManager.getConnection(jdbc:mysql://localhost/PAARsnp?user=rootpassw o rd=); % Could do it! % } catch (Exception e) { % Can't do it!BR %= e.getMessage() % % } % *** * *** And the resultant output: Can't do it! Server configuration denies access to data source *** * *** I know for a fact that the connection string is correct. However, I do not know where to go from here. I also know that I can successfully connect to this database from a PHP script, just not from Java code running within Tomcat. Thanks in advance for any help Matt Stine Software Engineer Hartwell Center for Bioinformatics and Biotechnology St. Jude Children's Research Hospital 332 N. Lauderdale St. Memphis, TN 38105-2794 Phone: 901.495.4602 Fax: 901.495.2945 [EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: Cannot connect Servlet/JSP running in Tomcat to MySQL Database
Try using the 2 argument DriverManager.getConnection method: DriverManager.getConnection(String connectString, Properties connectProperties); Where: connectString doesn't include the ?user=rootpassword= connectProperties is a java.util.Properties with elements user and password Also, could there be a MySQL filter that denies access to the DB from anything but PHP? -August --- Stine, Matt [EMAIL PROTECTED] wrote: Hi, I am unable to connect a servlet or jsp running in Tomcat to a MySQL database. Here are the particulars: Tomcat Version: 4.0.1 MySQL Version: 3.23.45 MySQL JDBC Driver Version: mm.mysql-2.0.4-bin.jar Linux Version: Red Hat 7.1 running Kernel Version 2.4.2-2smp Here is some sample code: *** %@ page import=java.sql.* % %! Connection c; % % try { Class.forName(org.gjt.mm.mysql.Driver).newInstance(); } catch (Exception e) {} try { c = DriverManager.getConnection(jdbc:mysql://localhost/PAARsnp?user=rootpasswo rd=); % Could do it! % } catch (Exception e) { % Can't do it!BR %= e.getMessage() % % } % *** And the resultant output: Can't do it! Server configuration denies access to data source *** I know for a fact that the connection string is correct. However, I do not know where to go from here. I also know that I can successfully connect to this database from a PHP script, just not from Java code running within Tomcat. Thanks in advance for any help Matt Stine Software Engineer Hartwell Center for Bioinformatics and Biotechnology St. Jude Children's Research Hospital 332 N. Lauderdale St. Memphis, TN 38105-2794 Phone: 901.495.4602 Fax: 901.495.2945 [EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] __ Do You Yahoo!? Send your FREE holiday greetings online! http://greetings.yahoo.com -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]