我正在使用如下所示的准备好的语句:
List<Integer> ids = new ArrayList<Integer>();
ids.add(SelectQueueRS.getInt("DTSId_int"));
PreparedStatement updateOriginal = connMain.prepareStatement(
"UPDATE test.selectiontable SET DTSStatusType_ti = 3, Queued_DialerIP_vch = ?" +
"WHERE DTSId_int IN (?)");
updateOriginal.setString(1, CurrRemoteIPAddress);
updateOriginal.setArray(2,connMain.createArrayOf("string", ids.toArray()));
updateOriginal.executeUpdate();
在线获取错误:
updateOriginal.setArray(2,connMain.createArrayOf("string", ids.toArray()));
这是我的堆栈跟踪:
Exception in thread "main" java.sql.SQLFeatureNotSupportedException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at com.mysql.jdbc.SQLError.notImplemented(SQLError.java:1329)
at com.mysql.jdbc.JDBC4Connection.createArrayOf(JDBC4Connection.java:56)
at project.Project.main(Project.java:295)
我浏览了一些旧的 Stackoverfollow 帖子,讨论了许多人在这里讨论的相同问题
建议不要使用createArrayOf
方法。
1) 我想知道是否可以更新我的 JDBC 驱动程序,这样我就不必更改代码中的任何方法?但是 在此之前,我必须检查 NEtbeans,我当前使用的是哪个版本。知道如何检查吗?
2)如果不是上述步骤,请告知我可以做哪些更改?
谢谢
我引用过的一些帖子:How to rectify the 'java.sql.SQLFeatureNotSupportedException' while using the createArrayOf() method
最佳答案
来自 statcktrace:
Exception in thread "main" java.sql.SQLFeatureNotSupportedException
很明显,您正在使用的驱动程序
不支持该功能。
- which version I am currently using.
使用您正在使用的驱动程序
实例,您可以找到其版本
。
int major = driver.getMajorVersion();
int minor = driver.getMinorVersion();
但是,据我所知,由于 MySQL 不支持自定义数据类型,例如 array
,因此更改驱动程序将不起作用。
- If not above step, please advise what changes I can do?
或者,您可以准备循环遍历值列表的查询并设置占位符,然后在执行之前设置值。
示例:
StringBuilder sqlSelect = new StringBuilder( 1024 );
sqlSelect.append( "UPDATE test.selectiontable " )
.append( "SET DTSStatusType_ti = 3, ")
.append( "Queued_DialerIP_vch = ? " )
.append( "WHERE DTSId_int IN ( " );
int paramCount = ids.size();
if( paramCount > 0 ) {
for( i = 0; i < paramCount; i++ ) {
sqlSelect.append( ( i > 0 ? ", ?" : "?" );
} // for each param
sqlSelect.append( " )" );
} // if ids list is not empty
// make the prepare statement (pst) with the above sql string
PreparedStatement pst =
connMain.prepareStatement( sqlStatement.toString() );
// now set the parameter values in the query
int paramIndex = 1;
pst.setString(paramIndex++, CurrRemoteIPAddress);
if( paramCount > 0 ) {
for( i = 0; i < paramCount; i++ ) {
pst.setLong( paramIndex++,
( (Integer)ids.get( i ) ).intValue() );
} // for each param
} // if ids list is not empty
pst.executeUpdate();
关于java - 尝试更新 mysql 驱动程序以摆脱 java.sql.SQLFeatureNotSupportedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22886133/