資料庫:Microsoft SQL Server 2008 R2 (SP1) - 10.50.2550.0 (X64) Jun 11 2012 16:41:53 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
使用函式庫:
1.Microsoft JDBC Driver 6.0 for SQL Server 6.0.8112.100
使用檔案:sqljdbc42.jar
2.commons-dbutils 1.6
使用檔案:commons-dbutils-1.6.jar
3.JTDS 1.3.1
使用檔案:jtds-1.3.1.jar
原本程式連結資料庫使用的JDBC 驅動程式為JTDS ,但為了升級資料庫版本為SQLServer 2014,需更換驅動程式,
故先使用原資料庫SQLServer 2008 R2測試連結,並更換JDBC驅動程式,但當中有使用 Apache Commons DbUtils 執行sql語法,
原本使用 JTDS 驅動程式可正常存取資料庫的模組卻產生了錯誤:
錯誤訊息:
[java] Caused by: java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerException: Unable to identify the table SELECT * FROM dbo.XXXTBL WHERE (COL1='rule1') Parameters: []
[java] at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:392)
[java] at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:351)
[java] at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:226)
[java] at myapp.utils.db.DbUtil.getBeanTypeResultSetList(DbUtil.java:1451)
原因是 AbstractQueryRunner.java中使用了getParameterMetaData()方法取得ParameterMetaData
,但Microsoft JDBC驅動程式卻不支援。
解決方法:
所有使用QueryRunner()建構子方法中參數 pmdKnownBroken 設定為 true,讓QueryRunner不執行getParameterMetaData()。
Constructor and Description |
---|
QueryRunner()
Constructor for QueryRunner.
|
QueryRunner(boolean pmdKnownBroken)
Constructor for QueryRunner that controls the use of
ParameterMetaData . |
QueryRunner(DataSource ds)
Constructor for QueryRunner that takes a
DataSource to use. |
QueryRunner(DataSource ds, boolean pmdKnownBroken)
Constructor for QueryRunner that takes a
DataSource and controls the use of ParameterMetaData . |
參考資料:
留言列表