Sqlgrammarexception

Asked

Viewed 59 times

1

Good night! Someone can help me with the error in my code, I followed the teacher’s steps but presents error in mine and not in his example. I am using the same dependencies. Follow the method snippet and the error.

public List<Person> findByLastName(String lastName){
    String jpql = "from Person p where p.lastName like ?";

    return find(jpql, lastName);
}   

private static void findByLastName() {
    List<Person> persons = new PersonDAO().findByLastName("Figueira");

    for (Person person : persons) {
        System.out.println(person.toString());      
    }
}

Makes that mistake:

com.mysql.jdbc.exceptions.jdbc4.Mysqlsyntaxerrorexception: 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 'from Person p Where p.lastname like 'Figueira'' at line 1

  • 1

    It looks like you’re trying to use JPQL as an SQL. Although they are similar, the two are mutually incompatible and should not be mixed. What the method find ago?

  • Victor, the "find" method was created to return a list based on a list of parameters.

1 answer

2

  • LR10, my Mysql and Hibernate dependencies have been updated to recent versions. i put as you spoke and gave the following error: [DEPRECATION] Encountered positional Parameter near line 1, column 76 in HQL: [SELECT p FROM br.com.devmedia.revjpa.Entity.Person p WHERE p.lastname LIKE ? ]. Positional Parameter are considered deprecated; use named Parameters or JPA-style positional Parameters Instead. Exception in thread "main" java.lang.Illegalargumentexception: Unknown Parameter position: 1.

  • Put the implementation of your find(jpql, lastname);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.