MySQLSyntaxErrorException
Hi there!
Im relatively new to spring and Database-Access with it, so I don't know where this error.message comes from...
Code:
SCHWERWIEGEND: Servlet.service() for servlet persons threw exception
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'persons.persons' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
Here's the code-snippet, where it is caused:
Code:
public List<Persons> getPersons() {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String SQL = "SELECT * FROM persons;";
List<Persons> person = jdbcTemplate.query(SQL, new PersonsMapper());
return person;
}
Its the row
Code:
List<Persons> person = jdbcTemplate.query(SQL, new PersonsMapper());
is there something wrong with my SQL-Statement, or is it the PersonsMapper?
the PersonsMapper-class:
public class PersonsMapper implements RowMapper<Persons> {
Code:
public Persons mapRow(ResultSet rs, int rowCount) throws SQLException {
// TODO Auto-generated method stub
Persons person = new Persons();
person.setId(rs.getInt("id"));
person.setFirst_name(rs.getString("first_name"));
person.setLast_name(rs.getString("last_name"));
person.setDate_of_birth(rs.getDate("date_of_birth"));
return person;
}
}
the controller-class looks like this:
Code:
@RequestMapping({"/","/persons"})
public String showHomePage(Map<String, Object> model) {
personsDAO = new PersonsDAO();
System.out.println("1.1");
personsDAO.getDataSource();
System.out.println("1.2");
model.put("persons", personsDAO.getPersons());
System.out.println("1.3");
return "persons";
}
and the -servlet.xml looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="lissy.persons"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost/persons"></property>
<property name="username" value="root"></property>
<property name="password" value="MySQL2012pwd"></property>
</bean>
<bean id="personsDAO" class="lissy.persons.PersonsDAO">
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>
does anybody have an idea what's wrong with this?
Thanks!!!