Hello all,
I’ve just started learning Spring and I’m using Spring MVC framework to create a simple webapp to take a name in a text field in one page and on submit the value is inserted in an MS access database and a greeting is displayed in another page saying “hello, <name>!”. While trying to deploy my simple Spring web app, I am getting the following errors.
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
.....
......
My applicationContext.xml and web.xml files are as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<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:jdbcodbcdriver:;DRIVER=Microsoft Access Driver (*.accdb);DBQ=D:\206132\usernamedb.accdb;" />
<property name="username" value="admin" />
<property name="password" value="password" />
</bean>
</beans>
The code to access the db is as below:
<pre><code>
package SpringClasses;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
public class Profile {
private String username;
private JdbcTemplate jt;
private DataSource dataSource;
public Profile() {
}
public Profile(String username) {
this.username = username;
}
public String getUsername() {
System.out.println("username " + username);
return username;
}
public void setUsername(String username) {
int rowsInserted;
jt = new JdbcTemplate(dataSource);
rowsInserted = jt.update("insert into usernamedb (username) values(?)",new Object[] { username });
System.out.println(rowsInserted);
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
}
</code></pre>
I am unable to figure out the reason for the connection timed error. I have also added this data base under control panel -> administrative tools -> Data Sources (ODBC) -> both User DSN and System DSN.
Help is much appreciated.
Thanks,
Neetu