Announcement Announcement Module
Collapse
No announcement yet.
MySQLSyntaxErrorException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!!!

  • #2
    Well I don't think there is any one to read your code, that is really written in very small font size, but I have an advice for you, if you even, can't remove the syntax error by yourself just left the programming LOLZ. Because syntax error is easy to detect by the coder himself. So, just try.

    Comment


    • #3
      Have you read the stacktrace?

      Code:
      Table 'persons.persons' doesn't exist
      Seems pretty clear to me?! You don't have a table named persons (you only have a schema).

      Comment


      • #4
        Sorry!!! I didn't mention that: This table exists, but it seems he doesn't find it...

        Comment


        • #5
          Trust me it doesn't, at least not in the schema/database you are connecting to... Also a schema isn't a table...

          Also your code is wrong (I strongly suggest a read on DI and IoC)... Basically your PersonDAO definition is useless as you are creating a new instance in your controller...
          Last edited by Marten Deinum; Oct 8th, 2012, 03:38 AM.

          Comment


          • #6
            Thanks for your hints! I will dive in DI and IoC (I thought I understood this...)..

            As it looks like, you have much more experience with spring than me, could you answer me some questions?
            Code:
            Table 'persons.persons' doesn't exist
            It seems like I haven't referenced this table properly (because I know it exists).. Could you give me some hints how to do this?
            Can you tell me whats wrong with my code?

            Comment


            • #7
              I also suggest you read up on MySQL...

              As mentioned before

              Originally posted by mdeinum
              Trust me it doesn't, at least not in the schema/database you are connecting to... Also a schema isn't a table...
              So as stated the table simply doesn't exists... It is either named differently (person?) or it isn't in the schema you are connecting to (persons)... Or the account you are connecting with doesn't have priviliges... This has nothing to do with java it has to do with your server setup.

              Comment

              Working...
              X