1
    public List<Hero> list() throws SQLException {
        return list(0, Short.MAX_VALUE);
    }

    public List<Hero> list(int start, int count) throws SQLException{

             Connection c = this.getConnection();                
             QueryRunner runner = new QueryRunner();
             String sql = "select * from hero order by id desc limit ?,? ";  
             Object params[] = {"start", "count" };                               
             List<Hero> heros = (List<Hero>) runner.query(c,sql,new BeanListHandler(Hero.class),params);     

             DbUtils.closeQuietly(c);    

             return heros;
    }

Before that I have imported Dbutils JAR that I need, like org.apache.commons.dbutils.handlers.BeanListHandler and org.apache.commons.dbutils.QueryRunner But after running my project, it goes wrongs whose message is :

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''start','count'' at line 1 Query: select * from hero order by id desc limit ?,? Parameters: [start, count]

I know that something wrong in program, but I dont want to find all, I just want to find part of my table using limit ?.? (I only know this sql sentence can do that).

Could u please help me?

Rajeev Sreedharan
  • 1,753
  • 4
  • 20
  • 30
Joshua Lee
  • 45
  • 8
  • You want to limit result just choose the number of returned row you want to return to b like limit 15; – Fady Saad Apr 20 '17 at 03:01
  • u misunderstand my meaning .i wanna know how to solve this wrong to make this project run successfully. This is just a method which i can use in another class . haven u see the int start and int count? – Joshua Lee Apr 20 '17 at 03:03
  • OK, tell me what exactly you want. – Fady Saad Apr 20 '17 at 03:03

1 Answers1

1

You're passing strings as your parameters, so it's running your SQL limit literally as LIMIT 'start','count'

Try this instead:

Object params[] = {start, count };

So that you're building a parameter array of your actual int values (now autoboxed to Integer)

Alex
  • 2,435
  • 17
  • 18