Java 8和JDBC:Access中的ODBC驱动程序

时间:2015-01-23 08:23:11

标签: java ms-access jdbc-odbc ucanaccess

从版本8开始,Java不再支持JDBC:ODBC驱动程序。 我尝试更改我的应用程序的源代码以使用UcanAccess Ver.2.0.9.3,但这会抛出许多异常,例如:

net.ucanaccess.jdbc.UcanaccessSQLException: unknown token:
---
net.ucanaccess.jdbc.UcanaccessSQLException: unexpected token: AS required: )

这是错误代码的示例:

    String selectString = "SELECT [Maintenance input Check Due List].InputRepairStation, [Maintenance input Check Due List].[Interval (Mos)], [Maintenance input Check Due List].InputAircraftHours, [Maintenance input Check Due List].InputAircraftLandings,  [Maintenance input Check Due List].Check, [Maintenance input Check Due List].Title, [Maintenance input Check Due List].InputNumber,[Maintenance input Check Due List].InputDescription, [Maintenance input Check Due List].AircraftCurrentTSN, [Maintenance input Check Due List].AircraftCurrentCSN, [Maintenance input Check Due List].Aircraft, [Maintenance input Check Due List].InputDateOUT, [Maintenance input Check Due List].[Interval (Hrs)], [Maintenance input Check Due List].[Interval(Ldgs)], [Maintenance input Check Due List].NextDueCheckMonth, [Maintenance input Check Due List].NextDueCheckHours, [Maintenance input Check Due List].NextDueCheckLdgs, [Maintenance input Check Due List].RemainCheckMonth, [Maintenance input Check Due List].RemainCheckHours,[Maintenance input Check Due List].RemainCheckLdgs, [Maintenance Schedule Check].MSC_Input, [Maintenance input Check Due List].Check "
            + "FROM [Maintenance input table] RIGHT JOIN ([Maintenance Schedule Check] RIGHT JOIN ("
            + "SELECT  [Maintenance input table].InputRepairStation, [Maintenance input table].InputAircraftHours, [Maintenance input table].InputAircraftLandings, [Check Table].Check, [Check Table].Title, [Maintenance input table].InputNumber, [Maintenance input table].InputDescription,[Aircraft].AircraftCurrentTSN,[Aircraft].AircraftCurrentCSN, [Check Table].Aircraft, [Maintenance input table].InputDateOUT,  [Check Table].[Interval (Mos)], [Check Table].[Interval (Hrs)], [Check Table].[Interval(Ldgs)], IIf([Interval (Mos)] Is Null,Null,DateAdd('m',[Interval (Mos)],[InputDateOUT])) AS NextDueCheckMonth, [Interval (Hrs)]+[InputAircraftHours] AS NextDueCheckHours, [Interval(Ldgs)]+[InputAircraftLandings] AS NextDueCheckLdgs, IIf([NextDueCheckMonth] Is Null,Null,DateDiff('d',Now(), [NextDueCheckMonth],1,1)) AS RemainCheckMonth, IIf([NextDueCheckHours] Is Null,Null,[NextDueCheckHours]-[AircraftCurrentTSN]) AS RemainCheckHours, [NextDueCheckLdgs]-[AircraftCurrentCSN] AS RemainCheckLdgs "
            + "FROM (([Aircraft] INNER JOIN [Check Table] ON [Aircraft].AicraftVar = [Check Table].Aircraft) INNER JOIN (((SELECT [Check Aircraft Status].CAS_Check, Max([Maintenance input table].InputDateOUT) AS MaxDeInputDateOUT "
            + "FROM ([Maintenance input table] INNER JOIN [Work Order table] ON [Maintenance input table].InputNumber = [Work Order table].WOInput) "
            + "INNER JOIN [Check Aircraft Status] ON [Work Order table].WONumber = [Check Aircraft Status].CAS_WO "
            + "GROUP BY [Check Aircraft Status].CAS_Check) AS [Maintenance input check wo select] "
            + "INNER JOIN [Maintenance input table] ON [Maintenance input check wo select].MaxDeInputDateOUT = [Maintenance input table].InputDateOUT)  INNER JOIN [Check Aircraft Status] ON [Maintenance input check wo select].CAS_Check = [Check Aircraft Status].CAS_Check) ON [Check Table].Check = [Check Aircraft Status].CAS_Check) INNER JOIN [Work Order table] ON ([Work Order table].WONumber = [Check Aircraft Status].CAS_WO) AND ([Maintenance input table].InputNumber = [Work Order table].WOInput) "
            + "WHERE ((([Check Table].Aircraft)='"
            + ac.getAicraftVAR()
            + "') AND (([Check Table].[Interval (Mos)]) Is Not Null)) "
            + "OR ((([Check Table].Aircraft)='"
            + ac.getAicraftVAR()
            + "') AND (([Check Table].[Interval (Hrs)]) Is Not Null)) "
            + "OR ((([Check Table].Aircraft)='"
            + ac.getAicraftVAR()
            + "') AND (([Check Table].[Interval(Ldgs)]) Is Not Null)) "
            + "ORDER BY [Check Table].[Interval (Mos)]) AS [Maintenance input Check Due List] "
            + "ON [Maintenance Schedule Check].MSC_Check = [Maintenance input Check Due List].Check) "
            + "ON [Maintenance input table].InputNumber = [Maintenance Schedule Check].MSC_Input "
            + "WHERE ((([Maintenance input Check Due List].RemainCheckMonth)<"
            + AircraftList.getMonth()
            + "*30) AND (([Maintenance input table].InputAircraft)='"
            + ac.getAicraftVAR()
            + "' Or ([Maintenance input table].InputAircraft) Is Null)) OR  "
            + "((([Maintenance input Check Due List].RemainCheckHours)<"
            + ac.hoursEstimation * AircraftList.getMonth()
            + ") AND (([Maintenance input table].InputAircraft)='"
            + ac.getAicraftVAR()
            + "' Or ([Maintenance input table].InputAircraft) Is Null)) OR "
            + "((([Maintenance input Check Due List].RemainCheckLdgs)<"
            + ac.ldgsEstimation
            * AircraftList.getMonth()
            + ") AND (([Maintenance input table].InputAircraft)='"
            + ac.getAicraftVAR()
            + "' Or ([Maintenance input table].InputAircraft) Is Null)) "
            + "ORDER BY IIf([RemainCheckMonth] IS Null, IIf([RemainCheckHours] IS Null, IIf([RemainCheckLdgs] IS Null, null, [RemainCheckLdgs]/"
            + ac.ldgsEstimation
            + "*30), IIf([RemainCheckLdgs] IS Null, [RemainCheckHours]/"
            + ac.hoursEstimation
            + "*30, IIF([RemainCheckHours]/"
            + ac.hoursEstimation
            + "*30< [RemainCheckLdgs]/"
            + ac.ldgsEstimation
            + "*30, [RemainCheckHours]/"
            + ac.hoursEstimation
            + "*30, [RemainCheckLdgs]/"
            + ac.ldgsEstimation
            + "*30))), IIf([RemainCheckHours] IS Null, IIf([RemainCheckLdgs] IS Null, RemainCheckMonth, IIF(RemainCheckMonth < [RemainCheckLdgs]/"
            + ac.ldgsEstimation
            + "*30, RemainCheckMonth, [RemainCheckLdgs]/"
            + ac.ldgsEstimation
            + "*30)), IIf([RemainCheckLdgs] IS Null, IIF(RemainCheckMonth <[RemainCheckHours]/"
            + ac.hoursEstimation
            + "*30, RemainCheckMonth, [RemainCheckHours]/"
            + ac.hoursEstimation
            + "*30), IIf([RemainCheckMonth] < [RemainCheckLdgs]/"
            + ac.ldgsEstimation
            + "*30, IIf([RemainCheckMonth] < [RemainCheckHours]/"
            + ac.hoursEstimation
            + "*30, [RemainCheckMonth], [RemainCheckHours]/"
            + ac.hoursEstimation
            + "*30), IIf([RemainCheckLdgs]/"
            + ac.ldgsEstimation
            + "*30<[RemainCheckHours]/"
            + ac.hoursEstimation
            + "*30, [RemainCheckLdgs]/"
            + ac.ldgsEstimation
            + "*30, [RemainCheckHours]/"
            + ac.hoursEstimation + "*30)))))";

这引发了以下异常:

net.ucanaccess.jdbc.UcanaccessSQLException: unexpected token: AS required: )

我的问题如下:

  • 是否有任何解决方案可以找到旧的和坏的,但功能齐全的JDBC:ODBC库因此我可以在我的代码中导入它吗?

  • 是否有解决办法绕过这些例外而不更改查询(那里有很多查询)?

1 个答案:

答案 0 :(得分:1)

请尝试使用当前的2.3.2替换ucanaccess发行版中的hsqldb.jar。(从hsqldb网站下载)。请注意,移植到hsqldb 2.3.2尚未完成,但在您的特定情况下,它可能会起作用。无论如何,感谢Gord能够在ucanaccess帮助论坛上重现这个问题。