Csv Jdbc:不支持 ResultSet.getRow()
如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过创建可滚动语句...
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);