gpt4 book ai didi

java - JOOQ 在调用 select() 时创建高逗号

转载 作者:行者123 更新时间:2023-11-30 09:59:57 25 4
gpt4 key购买 nike

完成本教程后,我想创建一个小的选择查询

但是当调用 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 '`'.

查询 复制到 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();
}

}

最佳答案

愚蠢的我。

正如@AlwaysLearning 提到的,我用错了方言!

而不是 SQLDialect.MYSQL 它应该是 SQLDialect.SQLSERVER2014

关于java - JOOQ 在调用 select() 时创建高逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58432684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com