如题,比如说,select * from table where name=nnn
如果查询出来有多列数据,怎样取呢?我只能去第一个啊。
我用的jdbc,executeQuery()语句
我是初学者,请多多指教,谢谢!

解决方案 »

  1.   

    String sql="select * from table where name=nnn";
    Statement smt = conn.createStatement();
    ResultSet rs = smt.executeQuery(sql);
    while (rs.next()) {
       <%=rs.getString("表的字段名") %>
    }
      

  2.   

    ResultSet做循环就行了。public List getfx_alarm_setting_info(String mkt_Code) {
    Connection conn = null;
    DBConnection dbConnection = null;
    Statement stmt = null;
    ResultSet rs = null; String sql = "select * from fx_alarm_setting_info where mkt_Code ='"
    + mkt_Code + "' and is_valid ='" + 1 + "' ";

    try {
    dbConnection = DBFactory
    .getConnection("CREPOInitAlarmData.getfx_alarm_setting_info");
    conn = dbConnection.connection;
    stmt = conn.createStatement();
    rs = stmt.executeQuery(sql);
    while (rs.next()) {
    Alarm_CodeList.add(rs.getString("alarm_code"));
    }
    } catch (SQLException e) {
    // TODO: handle exception
    } catch (ClassException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    } finally {
    try {
    if (rs != null) {
    rs.close();
    }
    if (stmt != null) {
    stmt.close();
    }
    if (!conn.isClosed()) {
    conn.close();
    }
    } catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
    }
    }
    return Alarm_CodeList; }
      

  3.   

    Select 之后返回一个结果集rs(ResultSet)
    然后用while循环遍历
    while(rs.next()){
      rs.getString(列名)
      rs.getInt(列名)
      .
      .
      .
    }