你的方法没有错。这样是可以得到字段里多值的。
如果你想得到其它字段的值:
while(rs.next()){
out.println(rs.getXXX("fName")) ;//XXX为与fName字段类型一样的方法。如:
out.println(rs.getInt("IntId")) ;
}
http://www.csdn.net/expert/topic/773/773734.xml?temp=.8216516

解决方案 »

  1.   

    字段里有很多值?你是说有多个字段?
    <tr>
           <td><%= rs.getString("Price") %></td>
            </tr>
    <tr>
           <td><%= rs.getString("其他字段") %></td>
            </tr>
      

  2.   

    我的意思是:
    <td><%= rs.getString("Price") %></td>
    Price字段里有很多数据。例如:
    包含 100元,200元,
    我现在用rs.getString("Price") 方法,只能取出100元
    我现在想取出200元,怎么取
      

  3.   

    应该可以取到啊!不知道你的bean怎么写的!
    jsp没问题!
      

  4.   

    如果一个字段里有很多值,rs.getString("Price")一次就能得出这个字段里的值。如果是100元,200元,300元,就以逗号为分割符取。
    你的意思好像是字段好多条纪录。
      

  5.   

    package com.db;import java.sql.*;
    import java.util.*;public class Books {  String error;
      Connection con;  public Books()   { }  public void connect() throws ClassNotFoundException,
                                   SQLException, 
                                   Exception {
        try {
          Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); 
          con = DriverManager.getConnection(
            "jdbc:oracle:thin:*************);
        } catch (ClassNotFoundException cnfe) {
          error = "ClassNotFoundException: Could not locate DB driver.";
          throw new ClassNotFoundException(error);
        } catch (SQLException cnfe) {
          error = "SQLException: Could not connect to database.";
          throw new SQLException(error);
        } catch (Exception e) {
          error = "Exception: An unknown error occurred while connecting " +
                  "to database.";
          throw new Exception(error);
        }
      }   public void disconnect() throws SQLException {
        try {
          if ( con != null ) {
            con.close();
          }
        } catch (SQLException sqle) {
          error = ("SQLException: Unable to close the database connection.");
          throw new SQLException(error);
        }
      }  public ResultSet viewBooks() throws SQLException, Exception {
        ResultSet rs = null;
        try  {
          String queryString = "SELECT * FROM BADWDJ where bdssod='*********' ";
          Statement stmt = con.createStatement();
          rs = stmt.executeQuery(queryString); 
        } catch (SQLException sqle) {
          error = "SQLException: Could not execute the query.";
          throw new SQLException(error);
        } catch (Exception e) {
          error = "An exception occured while retrieving books.";
          throw new Exception(error);  
        }
        return rs;
      }
    }
    我只能取出来一个
      

  6.   

    说错了
    ,是可以都取出来。
    但是,情况是这样的 我想在一个表格里只显示100元,在另一个表格里显示出来200元,这个怎么实现,
    用<td><%= rs.getString("Price") %></td>
    只能都显示出来
      

  7.   

    加判断啊!
    eg:
    String price = "";
    Vector temp = new Vector();
    while(rs.next())
    {
        price=(rs.getString("price")==null)?"":re.getString("price");
        if(price.equals("100"))
    %>
    <td><%=price%></td>
    <%
    else if(price.equals("200"))
    {
        temp.addElement(price);
    }
    }载在另一个表格中取出vector中的指显示即可:
      

  8.   

    我很菜,请多帮忙!!
    String queryString = "SELECT * FROM BADWDJ where bdssod='*********' ";
    在BADWDJ表格里面有字段bdssod,字段bdssod包含100元,200元,300元,400元,500元,600元1000元
    现在想分别显示出来,怎么写
      

  9.   

    最好把你的bean改写,把sql语句传进去:
    package com.db;import java.sql.*;
    import java.util.*;public class Books {  String error;
      Connection con;
      public Statement stmt = null;  public Books()   { }  public void connect() throws ClassNotFoundException,
                                   SQLException, 
                                   Exception {
        try {
          Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); 
          con = DriverManager.getConnection(
            "jdbc:oracle:thin:*************);
          stmt = con.creatStatement();   
        } catch (ClassNotFoundException cnfe) {
          error = "ClassNotFoundException: Could not locate DB driver.";
          throw new ClassNotFoundException(error);
        } catch (SQLException cnfe) {
          error = "SQLException: Could not connect to database.";
          throw new SQLException(error);
        } catch (Exception e) {
          error = "Exception: An unknown error occurred while connecting " +
                  "to database.";
          throw new Exception(error);
        }
      }   public void disconnect() throws SQLException {
        try {
       if ( stmt != null ) {
            stmt.close();
          }
             
    if ( con != null ) {
            con.close();
          }
        } catch (SQLException sqle) {
          error = ("SQLException: Unable to close the database connection.");
          throw new SQLException(error);
        }
      }  public ResultSet viewBooks(String sql) throws SQLException, Exception {
        ResultSet rs = null;
        try  {
          //String queryString = "SELECT * FROM BADWDJ where bdssod='*********' ";
          //Statement stmt = con.createStatement();
          rs = stmt.executeQuery(sql); 
        } catch (SQLException sqle) {
          error = "SQLException: Could not execute the query.";
          throw new SQLException(error);
        } catch (Exception e) {
          error = "An exception occured while retrieving books.";
          throw new Exception(error);  
        }
        return rs;
      }
    }这样的华你可以在页面上根据需要把所需的sql语句传给bean,方便一些。你使用得好象是Oracle,在Oracle中支付传比较是:where colname like '%100%'加条件查询也可,一次查出在分类也可,看数据量大小吧!
    因为不知道你得页面具体是一种什么需求,所以不能给出好的建议。
      

  10.   

    用price.indexOf("100")
    或price.substring(0,4)区100 price.substring(5,9)区200......
      

  11.   

    try:<%
    String sPrice = "100,200,300,400,500" ;
    java.util.Vector vPrice = new java.util.Vector() ;
    java.util.StringTokenizer stzp = new java.util.StringTokenizer(sPrice, ",");
        while(stzp.hasMoreTokens()){
    vPrice.addElement(stzp.nextToken()) ;
        }
    for (int i=0;i<vPrice.size();i++)
    out.println(vPrice.elementAt(i)+"<br>") ;
    %>
      

  12.   

    我的意思是在BADWDJ表格里面有字段Price,字段Price第一行为100元,第二行为200元,第二行为300元,第四行为400元。
    然后我在jsp页面里在不同的地方分别把第一行,第二行,第三行,第四行得值显示出来,怎么写。
      

  13.   

    try:<%
    java.util.Vector vPrice = new java.util.Vector() ;
    while(rs.next()){
    vPrice.addElement(rs.getString("Price")) ;
        }
    for (int i=0;i<vPrice.size();i++)
    out.println(vPrice.elementAt(i)+"<br>") ;
    %>
      

  14.   

    to Andrawu(Andrawu) 
    是不同的地方哎!呵呵!
      

  15.   

    /**试试以下的方法,我没有测试,不知道行不行**/
    /**先定义以下方法**/import java.util.StringTokenizer;public static java.util.ArrayList getTheValues(String strValue,String separator)
       {java.util.ArrayList arrValues=new java.util.ArrayList();    
        StringTokenizer st = new StringTokenizer(strValue,separator);    
        String tmp;
        while(st.hasMoreTokens())
          {tmp=st.nextToken();
           arrValues.add(tmp);
          }    
        return arrValues;
       }/**以上得到一个方法,历遍数组就可以得到没个值了。**/
    int arrSize=arrValues.size();
    for(int j=0;j<=arrSize;j++)
     {out.println(arrValues.get(j));}