完成本教程后,我想创建一个小的select Query。
但在调用fetch()时,返回了以下错误:
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 '`'.将query复制到SQL Server时,查询也不正确。
我该如何解决这个问题呢?查询本身是正确的(正确的列)。
代码是由codegen自动生成的。
主要方法:
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();
}
}发布于 2019-10-17 21:51:47
愚蠢的我。
正如@AlwaysLearning提到的,我用错了方言!
它应该是SQLDialect.SQLSERVER2014,而不是SQLDialect.MYSQL
https://stackoverflow.com/questions/58432684
复制相似问题