Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI History with MSSQL SQLServerException: Incorrect syntax near 'limit'. #105

Closed
sterlp opened this issue May 7, 2024 · 5 comments
Closed

Comments

@sterlp
Copy link
Contributor

sterlp commented May 7, 2024

image

com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'limit'.
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:259) ~[mssql-jdbc-12.4.2.jre11.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1695) ~[mssql-jdbc-12.4.2.jre11.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:648) ~[mssql-jdbc-12.4.2.jre11.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:567) ~[mssql-jdbc-12.4.2.jre11.jar:na]
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7675) ~[mssql-jdbc-12.4.2.jre11.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:4137) ~[mssql-jdbc-12.4.2.jre11.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:272) ~[mssql-jdbc-12.4.2.jre11.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:246) ~[mssql-jdbc-12.4.2.jre11.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:485) ~[mssql-jdbc-12.4.2.jre11.jar:na]
	at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-5.0.1.jar:na]
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-5.0.1.jar:na]
	at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:732) ~[spring-jdbc-6.1.6.jar:6.1.6]
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:658) ~[spring-jdbc-6.1.6.jar:6.1.6]
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:723) ~[spring-jdbc-6.1.6.jar:6.1.6]
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:748) ~[spring-jdbc-6.1.6.jar:6.1.6]
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:804) ~[spring-jdbc-6.1.6.jar:6.1.6]
	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.query(NamedParameterJdbcTemplate.java:218) ~[spring-jdbc-6.1.6.jar:6.1.6]
	at no.bekk.dbscheduler.ui.service.LogLogic.getLogsDirectlyFromDB(LogLogic.java:114) ~[db-scheduler-ui-1.1.2.jar:na]
	at no.bekk.dbscheduler.ui.service.LogLogic.pollLogs(LogLogic.java:57) ~[db-scheduler-ui-1.1.2.jar:na]
	at no.bekk.dbscheduler.ui.controller.LogController.pollLogs(LogController.java:40) ~[db-scheduler-ui-1.1.2.jar:na]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
@sterlp
Copy link
Contributor Author

sterlp commented May 7, 2024

I had a very brief look into the code, just a question: Why don't you use JPA here? I assume most projects would be fine with that?

Alternatively you may use the jdbcTemplate.setMaxRows(1);

@sterlp
Copy link
Contributor Author

sterlp commented May 7, 2024

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [select * from scheduled_execution_logs where time_started >= ? and time_finished <= ? order by time_finished desc limit 500]; SQL state [S0001]; error code [102]; Incorrect syntax near 'limit'.] with root cause

this would be correct:

select TOP 500 * from scheduled_execution_logs 
order by time_finished desc

@sterlp
Copy link
Contributor Author

sterlp commented May 13, 2024

here is my current fix for this issue:

    // queryBuilder.limit(DEFAULT_LIMIT);
    final NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    namedParameterJdbcTemplate.getJdbcTemplate().setMaxRows(500);
    return namedParameterJdbcTemplate.query(
        queryBuilder.getQuery(), queryBuilder.getParameters(), new LogModelRowMapper(showData, objectMapper));

@geirsagberg
Copy link
Collaborator

I agree, JPA or some other abstraction would be preferable to support more SQL engines.
In lieu of this, your fix seems nice, would you mind opening a PR?

sterlp added a commit to sterlp/db-scheduler-ui that referenced this issue May 14, 2024
- bekk#105
- bekk#107
- fixed how the static resources are copied, using maven tools to ensure it works on any OS.
geirsagberg pushed a commit that referenced this issue May 22, 2024
- #105
- #107
- fixed how the static resources are copied, using maven tools to ensure it works on any OS.
@sterlp
Copy link
Contributor Author

sterlp commented May 23, 2024

thanks works like a charm.

@sterlp sterlp closed this as completed May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants