views:

345

answers:

1

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.

A: 

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.

John
The stacktrace tells that it failed to parse the `/WEB-INF/applicationContext.xml` file and all the DB interaction is far beyond this and can thus not be the root cause of this all. The OP made the mistake to only read the message "connection timed out" instead of the entire trace.
BalusC