java获取数据库的值并返回

img


一模一样的语句在sql是正常显示的:

img


但是在java里就变这样了

img

请问是哪里出错了吗

这个东东,,,哪里有那么复杂,

要用ResultSet ,,请先这样;

while(rs.next()){
  ...
  ...
}

这是ResultSet的next方法解释

     * @return <code>true</code> if the new current row is valid;

     * <code>false</code> if there are no more rows
     * @exception SQLException if a database access error occurs or this method is
     *            called on a closed result set
     */
    boolean next() throws SQLException;

ResultSet的后,游标默认的第一行是标题行,不是数据行。

看上面你这个直返回了一行哈, 错误说的是结果集没有当前行。
看你代码,你是rs.getString(1); 应该是这里错了,你换成rs.getString(0);

你确定不应该是rs.getString(0)吗,你表里一共就一行,集合都是从0开始的,你去获取第1行,那不是空吗