ResultSet不处理其中包含CASE语句的sql查询

时间:2017-02-20 17:26:31

标签: java jdbc case

获取“无效数字”异常,resultSet在其中执行带有CASE语句的SQL查询。对于CASE语句,同样正常工作。
虽然我在SQL开发人员控制台中运行它时两个查询都运行良好 这是用PreparedStatement无法实现的吗? java代码:

public Optional<List<ServicesExtn>> fetchThreadUtilByRange(long cohClusterId, String serviceName, LocalDateTime lowTime, LocalDateTime highTime) {
List<ServicesExtn> dataList = new ArrayList<>();
ResultSet resultSet = null;
try (PreparedStatement preparedStatement = this.datasource.getConnection().prepareStatement(DatabaseQueriesEnum.MY_TESTING_QUERY.getQuery())) {    
preparedStatement.setLong(1, cohClusterId);
preparedStatement.setString(2, serviceName);
preparedStatement.setTimestamp(3, Timestamp.valueOf(lowTime));
preparedStatement.setTimestamp(4, Timestamp.valueOf(highTime));
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
ServicesExtn servicesExtn = new ServicesExtn();
servicesExtn.setServiceName(resultSet.getString("ServiceName"));    
servicesExtn.setRecordTime(resultSet.getTimestamp("RecordTime").toLocalDateTime());
servicesExtn.setTaskBacklog(resultSet.getFloat("FinalPercentage"));

SQL查询:

SELECT temp.Coh_Cluster_Id,
temp.ServiceName AS ServiceName,
node.MemberName,
temp.recordtime      AS RecordTime,
temp.THREADCOUNT     AS THREADCOUNT,
temp.THREADIDLECOUNT AS THREADIDLECOUNT,
CASE
WHEN temp.THREADCOUNT > 0
THEN ((THREADCOUNT-THREADIDLECOUNT) * 100.00) / THREADCOUNT
ELSE                   -1.00
END AS FinalPercentage
FROM NODE_TABLE node,
(SELECT service.Coh_Cluster_Id,
 service.ServiceName,
 service.NodeId,
 service.recordtime,
 service.THREADCOUNT,
 service.THREADIDLECOUNT
FROM CACHE_TABLE cache
RIGHT OUTER JOIN SERVICE_TABLE service
ON cache.Coh_Cluster_Id    = service.Coh_Cluster_Id
AND cache.ServiceName      = service.ServiceName
AND cache.recordtime       = service.recordtime
WHERE service.ServiceName  = ?
AND service.coh_cluster_id = ?
) temp
WHERE node.Coh_Cluster_Id = temp.Coh_Cluster_Id
AND node.ClusterMemberId  = temp.NodeId
AND temp.recordtime       = node.recordtime
AND temp.RECORDTIME BETWEEN ? AND ?
ORDER BY temp.recordtime ASC

错误堆栈跟踪:

com.wellsfargo.ec.util.NonFatalException: Error getting ThreadUtilPercentage details for chart ORA-01722: invalid number

at com.wellsfargo.ec.dao.CoherenceServicesDAO.fetchThreadUtilByRange(CoherenceServicesDAO.java:324)
at com.wellsfargo.ec.dao.CoherenceServicesDAOTest.testFetchThreadUtilByRange(CoherenceServicesDAOTest.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Caused by: java.sql.SQLSyntaxErrorException: ORA-01722: invalid number

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:208)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:886)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1175)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1296)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3613)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3657)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1495)
at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:83)
at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:83)
at com.wellsfargo.ec.dao.CoherenceServicesDAO.fetchThreadUtilByRange(CoherenceServicesDAO.java:302)
... 25 more

0 个答案:

没有答案