recklessGreed
recklessGreed

Reputation: 139

JOOQ creates high comma when calling select()

With finishing the tutorial I wanted to create a small select Query.

But when calling fetch() following Error returned:

org.jooq.exception.DataAccessException: SQL [select `LECTURE_DB`.`dbo`.`STUDENT`.`ID`, `LECTURE_DB`.`dbo`.`STUDENT`.`FIRSTNAME`, `LECTURE_DB`.`dbo`.`STUDENT`.`LASTNAME`, `LECTURE_DB`.`dbo`.`STUDENT`.`YEAR_OF_BIRTH`, `LECTURE_DB`.`dbo`.`STUDENT`.`GENDER` from `LECTURE_DB`.`dbo`.`STUDENT` -- SQL rendered with a free trial version of jOOQ 3.12.1]; Falsche Syntax in der Nähe von '`'.
at org.jooq_3.12.1.MYSQL.debug(Unknown Source)
at org.jooq.impl.Tools.translate(Tools.java:2717)
at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:755)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:383)
at org.jooq.impl.AbstractResultQuery.fetch(AbstractResultQuery.java:353)
at org.jooq.impl.SelectImpl.fetch(SelectImpl.java:2693)
at de.esteam.lecturedb.jooq.Classes.Startup.main(Startup.java:32)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Falsche Syntax in der Nähe von '`'.

When Copying the query into SQL Server the query is also incorrect.

How can i fix this? The query per se is correct (correct columns).

The Code was autogenerated by codegen.

The Main Method:

public static void main(String[] args)
{
    // TODO Auto-generated method stub
    String userName = "SampleUser";
    String password = "SamplePwd";
    String url = "jdbc:sqlserver://SampleURL;databaseName=LECTURE_DB";

    // Connection is the only JDBC resource that we need
    // PreparedStatement and ResultSet are handled by jOOQ, internally
    try  {
        Connection conn = DriverManager.getConnection(url, userName, password);
        DSLContext create = DSL.using(conn, SQLDialect.MYSQL);
        Result<Record> result = create.select().from(Student.STUDENT).fetch();

        for (Record r : result) {
            Integer id = r.getValue(Student.STUDENT.ID);
            String firstName = r.getValue(Student.STUDENT.FIRSTNAME);
            String lastName = r.getValue(Student.STUDENT.LASTNAME);

            System.out.println("ID: " + id + " first name: " + firstName + " last name: " + lastName);
        }
    } 

    // For the sake of this tutorial, let's keep exception handling simple
    catch (Exception e) {
        e.printStackTrace();
    }

}

Upvotes: 2

Views: 106

Answers (1)

recklessGreed
recklessGreed

Reputation: 139

Stupid me.

As @AlwaysLearning mentioned I used the wrong dialect!

Instead of SQLDialect.MYSQL it should be SQLDialect.SQLSERVER2014

Upvotes: 1

Related Questions