sql 字符串转数组_将SQL Query结果转换为字符串数组

I am making queries to a SQLite3 database in Java using the SQLiteJDBC (Java JDBC driver for SQLite).

If I make the SQL query SELECT name, pass FROM loginTable WHERE name='%s'; is there a function to Return OR Convert the name & pass strings returned from the query into a String array or ArrayList?

The following code attempts to put the queries return into an array list but it fails, I know that the SQL database is fine & the query I make because when I do this in command line it works.

ArrayList result = new ArrayList();

ResultSet rs = stat.executeQuery( "SELECT ..." );

for (int i=0; rs.next(); i++)

{

result.add( rs.getString(i) );

}

It fails because the table loginTable has the columns: Index, name, pass. So looking at above, when i=0, & I go rs.getString(0), it tries to get the string in the Index column.

The error output is

java.sql.SQLException: column 0 out of bounds [1,1]

Does anyone know how I can put all results from an SQL query(ResultSet object) in an ArrayList or array?

解决方案

In JDBC, the columns are indexed starting from 1, not 0.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值