1
votes

I’m trying to deploy a simple Spring app and getting a “connection timed out ” error. My app tries to take a text input from the user in one jsp, insert that value under username in the db and then display that name in another jsp along with a greeting eg: "hello, "

My environment:

  1. OS: Windows XP professional
  2. Server : Tomcat 6
  3. IDE: Eclipse
  4. DB: MS Access 2007

I am getting the error below:

SEVERE: Context initialization failed

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.net.ConnectException: Connection timed out: connect

java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.Socket.connect(Socket.java:520) at java.net.Socket.connect(Socket.java:470) at sun.net.NetworkClient.doConnect(NetworkClient.java:157) at sun.net.www.http.HttpClient.openServer(HttpClient.java:388) at sun.net.www.http.HttpClient.openServer(HttpClient.java:523) at sun.net.www.http.HttpClient.(HttpClient.java:231) at sun.net.www.http.HttpClient.New(HttpClient.java:304) at sun.net.www.http.HttpClient.New(HttpClient.java:321)

SEVERE: Servlet /SpringExample threw load() exception

java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.Socket.connect(Socket.java:520) at java.net.Socket.connect(Socket.java:470) at sun.net.NetworkClient.doConnect(NetworkClient.java:157)

The code to access the db is as below:

//in the profile.java class

public void setUsername(String username) {
              int rowsInserted;
              setDataSource(dataSource);
             jt = new JdbcTemplate(dataSource);
             rowsInserted = jt.update("insert into usernamedb (username) values(?)",new Object[] { username });
             System.out.println(rowsInserted);
             }

in the profileFormController.java class

protected ModelAndView onSubmit(Object command)
    {
        Profile profile = (Profile) command; 
        String greeting = "Hello," + profile.getUsername() + "!";
        //System.out.println(greeting);
        profile.setUsername(profile.getUsername());
        return new ModelAndView("greetingDisplay", "greeting", greeting);
    }

To set up the DNS, in the ODBC sources I have set “usernamedb” as a DNS source by the user. I am not able to figure out the root cause for this error.

2
applicationContext.xml: <bean id="profile" class= "SpringExample.Profile"> <property name="dataSource" ref="dataSource"></property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" scope="singleton" destroy-method="close"> <property name="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver"/> <property name="url" value="jdbc:odbc:usernamedb" /> <property name="username" value="admin" /> <property name="password" value="password" /> </bean> - neetu
can you ping usernamedb? - Bozho
Sorry, didnt get your question. How can I ping the db? Secondly, I tried running the program without the DB connecivity and thats giving the same error as well. - neetu
I mean "the host where usernamedb" resides. but it's probably localhost. Give the whole spring config, by editing your question. - Bozho
The problem has nothing to do with the DB/JDBC code. The problem is in parsing the spring XML file. It is trying to download something from the internet over HTTP, but failed because the HTTP connection timed out. Please edit your question to remove the irrelevant DB code and post the /WEB-INF/applicationContext.xml along with the entire stacktrace. - BalusC

2 Answers

0
votes

First I would check to see if your db server is running. If it is, make sure you are trying to connect to it at the right address at the right port number, and if you are giving it the right username and password.

If all of those seem to be working you may also need to check that your db server will accept connections from the your address.

0
votes

In case, any one is still looking for a resolution, take a look at the DTD definition in your /WEB-INF/applicationContext.xml including the dtd version

If you can't find anything wrong, try moving to the XML Schema style of configuration. Please see http://docs.spring.io/spring/docs/current/spring-framework-reference/html/xsd-config.html#xsd-config-body