?
Solved

Web Server - Connectivity Issue

Posted on 2005-04-11
12
Medium Priority
?
181 Views
Last Modified: 2010-04-01
Hi
I am connecting to a remote DB using the following code:

      Context ic = new InitialContext();
      DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/test");
      Connection conn = ds.getConnection();
      Statement stmt = conn.createStatement();

Server.xml is configured appropriately and everything is working fine.

I have an issue that if the DB Server is restarted for what ever reason, I need to restart Tomcat.

Is there any way of doing a DB restart without having to restart Tomcat???

Cheers
Angus
0
Comment
Question by:amacfarl
12 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 13752103
what database are you using?

Can you post your resource definition?

(be sure to XXX out the password/hostname) ;-)

Tim
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13752119
and what exception are you getting?

And what version of Tomcat are you using?
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13752157
You don't have multiple copies of these do you, i.e. in your webapp/WEB-INF/lib:
Jakarta-Commons DBCP 1.0, Jakarta-Commons Collections 2.0,  Jakarta-Commons Pool 1.0
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 29

Expert Comment

by:bloodredsun
ID: 13752167
Also, have you set-up your datasource so that it conects automatically?

E.g. for MySql

    <parameter>
      <name>url</name>
      <value>jdbc:mysql://localhost:3306/javatest?autoReconnect=true</value>
    </parameter>

from http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13752181
>>Also, have you set-up your datasource so that it conects automatically?

Should be re-connects automatically id you're using MySQL.
0
 
LVL 2

Author Comment

by:amacfarl
ID: 13752431
Here is my Server.xml relevant code:

The issue happens on two occassions.  Firstly if I deploy an updated war file, I then need to restart the Tomcat before connection works + When the DB server connection is lost due to a restart, I need to restart the Tomcat Server again.

The Error Message that I am getting are varied;

INFO   | jvm 1    | 2005/04/11 08:16:56 | EXCEPTION: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Broken pipe
and
INFO   | jvm 1    | 2005/04/11 08:16:50 | EXCEPTION: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Connection reset


 <Context path="/sc" docBase="../webapps/sc" debug="1" reloadable="true">
  <Resource name="jdbc/test" auth="Container" type="javax.sql.DataSource" />
 <ResourceParams name="jdbc/test">
 <parameter>
  <name>factory</name>
  <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
  </parameter>
 <parameter>
  <name>maxActive</name>
  <value>100</value>
  </parameter>
 <parameter>
  <name>maxIdle</name>
  <value>30</value>
  </parameter>
 <parameter>
  <name>maxWait</name>
  <value>10000</value>
  </parameter>
 <parameter>
  <name>username</name>
  <value>XXXXXXX</value>
  </parameter>
 <parameter>
  <name>password</name>
  <value>XXXXXXX</value>
  </parameter>
 <parameter>
  <name>driverClassName</name>
  <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
  </parameter>
 <parameter>
  <name>url</name>
  <value>jdbc:microsoft:sqlserver://XXXXXXXX.net\\Production</value>
  </parameter>
  </ResourceParams>
  </Context>
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13752506
try adding:

<parameter>
<name>validationQuery </name>
<value>SELECT 1 FROM dual </value>
</parameter>

to your resourceparams, replacing:

SELECT 1 FROM dual

with a SELECT statement that should succeed in all cases with SQLServer 2000...

Might help...

Tim
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13752509
<parameter>
  <name>validationQuery</name>
  <value>SELECT 1 FROM dual</value>
</parameter>

sorry... (no spaces after both attributes)
0
 
LVL 29

Accepted Solution

by:
bloodredsun earned 1500 total points
ID: 13752516
I think it's an issue with the db driver not having the capability to re-connect, see this thread http://www.javakb.com/Uwe/Forum.aspx/java-databases/1495/SQLServer-2000-Driver-for-JDBC-behaviour-on-SQL-Server-restart

Fo some it's a feature (e.g. transactional apps that depend on continuity), for others a problem (web apps).
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13752540
the validationQuery may solve it...
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13752719
I don't know enough about databases but the link I posted does mention that and also another parameter,  testWhileIdle="true"...
0
 
LVL 1

Expert Comment

by:vijaydogra
ID: 13778421
According to bloodredsun and his link the driver doesnot reconnect when the database is restarted. So either you have to write a code that reconnects to the database on failure or restart the server
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
With more and more companies allowing their employees to work remotely, it begs the question: What are some of the security risks involved with remote employees and what actions should we take to secure them?
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question