简体   繁体   English

JDBC 错误:AbstractMethodError:com.microsoft.sqlserver.jdbc.SQLServerConnection.createArrayOf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/sql/Array

[英]JDBC ERROR : AbstractMethodError: com.microsoft.sqlserver.jdbc.SQLServerConnection.createArrayOf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/sql/Array

Hi am just selecting Data from SQL SERVER and stroing it in Result set.嗨,我只是从 SQL SERVER 中选择数据并将其放入结果集中。 I am getting below error.我得到低于错误。

**JDBC ERROR : AbstractMethodError: com.microsoft.sqlserver.jdbc.SQLServerConnection.createArrayOf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/sql/Array**

The problem with this below line下面这行的问题

    java.sql.Array sqlarray = sqlcon.createArrayOf(null, rowValues.toArray());

I am not sure why this issue occurs and what exact parameter should I pass createArrayOf().. Please help for this below issue我不确定为什么会出现这个问题以及我应该传递什么确切的参数 createArrayOf().. 请帮助解决以下问题

Here is full my code这是我的完整代码

    public void getDatafromsql(ArrayList rowValues) throws SQLException,ClassNotFoundException 
    {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    System.out.println("SQL Server Start Connecting ");
    Connection sqlcon = DriverManager
            .getConnection(s_url, s_username, s_password);
    System.out.println("Sql server Connection valid");
    System.out.println(rowValues);
    PreparedStatement s1 = sqlcon.prepareStatement("SELECT TOP 6 myid,document,name FROM table1 where DATEMODIFIED between ? and ? and myid in (?)");
    s1.setTimestamp( 1,V_DOC_LAST_REFRESH_TIMESTAMP);
    s1.setTimestamp( 2,V_DOC_CURRENT_REFRESH_TIMESTAMP);
    //Below line throwing error
    java.sql.Array sqlarray = sqlcon.createArrayOf(null, rowValues.toArray());
    s1.setArray(3, sqlarray);
    sql_rs = s1.executeQuery();
    setdataOracle(sql_rs);
    System.out.println("SQL Server Storage Completed ");
    sqlcon.close();
    }

The SQL Server JDBC driver doesn't support that method: SQL Server JDBC驱动程序不支持该方法:

public java.sql.Array createArrayOf(String typeName,

        Object[] elements) throws SQLException {

    // Not implemented

    throw new SQLFeatureNotSupportedException(SQLServerException.getErrString("R_notSupported"));

}

https://github.com/Microsoft/mssql-jdbc/blob/master/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java https://github.com/Microsoft/mssql-jdbc/blob/master/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

Instead use Table Valued Parameters , or pass the data as XML , JSON , or CSV and parse it on the server. 而是使用Table Valued Parameters或将数据作为XMLJSONCSV传递并将其解析到服务器上。

Did you tried call 你试过打电话吗

sqlcon.createArrayOf("INT", rowValues.toArray());

or 要么

sqlcon.createArrayOf("integer", rowValues.toArray());

or some data type your data base system supports. 或数据库系统支持的某些数据类型。 If nothing works, probably the driver you use does not support arrays. 如果没有任何效果,则可能是您使用的驱动程序不支持数组。 In this case create placeholders (?) "hard coded" and use 在这种情况下,请创建占位符(?)“硬编码”并使用

s1.setInt(i, intValue);

in a loop (where i is 3 to (array size + 3)) instead of 在一个循环中(我是3到(数组大小+ 3))而不是

s1.setArray(3, sqlarray);

Example how to use table valued parameters as a solution for SQL Server since createArrayOf() is not supported yet.示例如何使用表值参数作为 SQL Server 的解决方案,因为尚不支持 createArrayOf()。

private void createTableType() throws SQLException, IOException, ClassNotFoundException {
    try(Statement stmt = DBUtils.dbConnect().createStatement()){
        stmt.executeUpdate("IF NOT EXISTS (SELECT * FROM sys.types WHERE is_table_type = 1 AND name = 'Codes' ) " +
                "BEGIN CREATE TYPE dbo.Codes AS TABLE (Code VARCHAR(25)) END");
    }catch (ClassNotFoundException | SQLException e){
        if(e instanceof SQLException){
            DBUtils.printSQLException((SQLException) e);}
        e.printStackTrace();
        throw e;
    }
}

public void tableValuedParamQuery(List<String> params) throws IOException, SQLException, ClassNotFoundException {
    try {
        createTypeTable();
        SQLServerPreparedStatement ssps = (SQLServerPreparedStatement) dbConnect().prepareStatement(
                "SELECT * FROM dbo.Products p" +
                     "INNER JOIN ? AS c ON c.Code = p.Code"
        );
        SQLServerDataTable dt = new SQLServerDataTable();
        dt.addColumnMetadata("Codes", Types.VARCHAR);
        params.forEach(e -> {
            try {
                dt.addRow(e);
            } catch (SQLServerException ex) {
                ex.printStackTrace();
            }
        });
        ssps.setStructured(1, " dbo.Codes", dt);
        ResultSet rs = ssps.executeQuery();
    }catch (ClassNotFoundException | SQLException e){
        if(e instanceof SQLException){
            DBUtils.printSQLException((SQLException) e);}
        e.printStackTrace();
        throw e;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Sheet 导入 Ljava.lang.Object 错误 - Google Sheet Import Ljava.lang.Object error “[Ljava.lang.Object;@”是什么意思? - What does "[Ljava.lang.Object;@" mean? checkBoxGroup:typeof返回[Ljava.lang.String - checkBoxGroup: typeof return [Ljava.lang.String appendRow 返回 [Ljava.lang.Object;@ 而不是值 - appendRow returns [Ljava.lang.Object;@ instead of values 消息说 [Ljava.lang.Object] 被传递代替值 - Message saying [Ljava.lang.Object] being delivered in place of values 将Firebase集成到react-native中时出错。 类LCom / google / firebase / auth / FireBaseAuth中没有虚拟方法getLanguageCode()Ljava / lang / String - Error while integrating firebase in react-native. No Virtual method getLanguageCode()Ljava/lang/String in class LCom/google/firebase/auth/FireBaseAuth java.lang.NoSuchMethodError: jdk.nashorn.internal.runtime.ECMAException.getEcmaError()Ljava/lang/Object; - java.lang.NoSuchMethodError: jdk.nashorn.internal.runtime.ECMAException.getEcmaError()Ljava/lang/Object; 在 Apps 脚本中接收 [Ljava.lang.Object(将附件名称从 Gmail 带到表格) - Receiving [Ljava.lang.Object in Apps Script (bringing attachment name from Gmail to Sheets) 来自Java Applet的调用方法,其中Javascript返回[Ljava.lang.String; @ 7ac79dfa - Calling method from Java Applet with Javascript returning [Ljava.lang.String;@7ac79dfa 如何使用sheets.AppendRow? 我一直在所有单元格中收到错误 [Ljava.lang.Object;@29080d11 - How do I use sheets.AppendRow? I keep receiving an error [Ljava.lang.Object;@29080d11 in all the cells
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM