Hi there!
Im relatively new to spring and Database-Access with it, so I don't know where this error.message comes from...
Here's the code-snippet, where it is caused: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)
Its the rowCode:public List<Persons> getPersons() { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String SQL = "SELECT * FROM persons;"; List<Persons> person = jdbcTemplate.query(SQL, new PersonsMapper()); return person; }is there something wrong with my SQL-Statement, or is it the PersonsMapper?Code:List<Persons> person = jdbcTemplate.query(SQL, new PersonsMapper());
the PersonsMapper-class:
public class PersonsMapper implements RowMapper<Persons> {
the controller-class looks like this: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; } }
and the -servlet.xml 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"; }
does anybody have an idea what's wrong with 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>
Thanks!!!


Reply With Quote