试图更新mysql驱动程序以摆脱java.sql.SQLFeatureNotSupportedException [英] trying to update mysql driver to get rid of java.sql.SQLFeatureNotSupportedException
问题描述
我正在使用如下的准备好的语句:
I am using Prepared Statement like the following :
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)
我浏览过一些Stackoverfolow的旧帖子,在这里讨论了许多人遇到的相同问题
建议不要使用createArrayOf
方法.
I have gone through some old Stackoverfolow posts discussing about the same issues here where many people
have suggested not to use createArrayOf
method.
1)我想知道是否可以更新我的JDBC驱动程序,以便不必更改代码中的任何方法? 在此之前,我将需要检入NEtbeans(我当前使用的是哪个版本).知道如何检查吗?
1) I am wondering, if I can update my JDBC driver so that I don't have to change any method in my code?But before that, I will have to check in NEtbeans, which version I am currently using. Any idea how to check that?
2)如果没有执行上述步骤,请告知我可以做些什么更改?
2) If not above step, please advise what changes I can do?
谢谢
我引用了一些帖子:如何使用在使用createArrayOf()方法时纠正"java.sql.SQLFeatureNotSupportedException"
推荐答案
从statcktrace中获取:
From the statcktrace:
Exception in thread "main" java.sql.SQLFeatureNotSupportedException
非常清楚,您正在使用的 Driver
不支持该功能.
it is very clear that the feature is not supported by Driver
, you are using.
- 我当前正在使用哪个版本.
- which version I am currently using.
使用正在使用的Driver
的实例,可以找到其version
.
Using the instance of the Driver
you are working with, you can find its version
.
int major = driver.getMajorVersion();
int minor = driver.getMinorVersion();
但是,由于MySQL不支持自定义数据类型(如array
),因此AFAIK不能更改驱动程序.
But, AFAIK, as MySQL does not support custom data types, like array
, changing the driver will not work.
- 如果不执行上述步骤,请告知我可以做些什么更改?
- If not above step, please advise what changes I can do?
或者,您可以准备查询循环遍历值列表并设置占位符,然后在执行之前设置值.
Alternatively, you can prepare the query looping through the list of values and set the place holders and then set values before execute.
示例:
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();
这篇关于试图更新mysql驱动程序以摆脱java.sql.SQLFeatureNotSupportedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!