Csv Jdbc:不支持 ResultSet.getRow()

发布于 2024-10-19 21:41:01 字数 1101 浏览 2 评论 0原文

如何在 CsvJdbc 中启用 ResultSet.getRow()?

(这是一个应该返回当前行号的函数)

它似乎依赖于 isScrollable 成员。如果有人以前遇到过这个问题,你是如何解决的?

  • 这是我需要在传入的 Properties 对象中设置的属性吗?
  • 我是否需要“清理”或以某种方式修改我的 CSV 文件?

谢谢!


更多信息

我使用的应用程序能够从任何 JDBC 源导入数据。我需要从 CSV 文件中获取一些数据,因此我使用 CsvJdbc。此应用程序需要访问其导入的每行数据的行号,不幸的是 CsvResultSet#getRow() 抛出异常,抱怨“Csv Jdbc : ResultSet.getRow() 不受支持”。

以下是实现。 CsvJdbc 中的 getRow() 方法 (1.0.5)

/**
 * Retrieves the current row number.  The first row is number 1, the
 * second number 2, and so on.
 *
 * @return the current row number; <code>0</code> if there is no current row
 * @exception SQLException if a database access error occurs
 */
public int getRow() throws SQLException {
    if (this.isScrollable == ResultSet.TYPE_SCROLL_SENSITIVE) {
        return currentRow;
    } else {
      throw new UnsupportedOperationException(
            "ResultSet.getRow() unsupported");
    }
}

查看源代码的其余部分,似乎设置 isScrollable 成员属性的唯一位置是在构造函数并作为默认值。

How do I enable ResultSet.getRow() in CsvJdbc?

(this is a function that is supposed to return the current row number)

It appears to be dependent on an isScrollable member. If anyone has encountered this before, how do you work around it?

  • Is it a property I need to set in the Properties object passed in?
  • Would I need to "sanitize" or somehow modify my CSV files in any way?

Thanks!


More Info

An application I use has the capability of importing data from any JDBC source. I need to get some data from CSV files into it, hence I'm using CsvJdbc. This application needs to access the row numbers of each line of data it imports, and unfortunately CsvResultSet#getRow() throws an exception, complaining that "Csv Jdbc : ResultSet.getRow() unsupported".

The following is the impl. of the getRow() method in CsvJdbc (1.0.5)

/**
 * Retrieves the current row number.  The first row is number 1, the
 * second number 2, and so on.
 *
 * @return the current row number; <code>0</code> if there is no current row
 * @exception SQLException if a database access error occurs
 */
public int getRow() throws SQLException {
    if (this.isScrollable == ResultSet.TYPE_SCROLL_SENSITIVE) {
        return currentRow;
    } else {
      throw new UnsupportedOperationException(
            "ResultSet.getRow() unsupported");
    }
}

Looking through the rest of the source it seems that the only place that the isScrollable member property is set is in the constructor and as a default value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤凫 2024-10-26 21:41:01

您是否尝试过创建可滚动语句...

Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

Have you tried creating a scrollable statement...

Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文