package ywfx;/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/import java.sql.*;
public class Connect1 {
  String sDBDriver = "com.informix.jdbc.IfxDriver";
  String url = "jdbc:informix-sqli://192.168.1.100:8888/ywfx:INFORMIXSERVER=ywfx_tcp;user=ywfx;password=ywfx";
  Connection conn = null;
  ResultSet rs = null;
  public Connect1() {
    try {
        Class.forName(sDBDriver);
        }
        catch (java.lang.ClassNotFoundException e) {
        System.err.println("Connect1():" + e.getMessage());
        }
  }  public ResultSet executeQuery(String sql) {
    rs = null;
    try {
        conn = DriverManager.getConnection(url);
        Statement stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);
        }
        catch (SQLException ex) {
        System.err.println("co.executeQuery:" + ex.getMessage());
        }
        return rs;
  }  public ResultSet branch() {
     String sql="select branch_no,branch_name from branch";
     try{
          conn = DriverManager.getConnection(url);
          PreparedStatement ps = conn.prepareStatement(sql);
          ResultSet res = ps.executeQuery(); 
          return res;
        }
        catch(Exception e){
          return null;
        }
    }
}请问如何在jsp网页中获取return res的返回值。

解决方案 »

  1.   

    在Servlet中new Connect1();
    完了调用executeQuery();
    对返回结果做一定处理;
    最后request.setAttribute("Result",res);
    大概就这么个过程!
      

  2.   

    在jsp中要用request.getAttribute()取出结果值!
      

  3.   

    把return返回的数据发送到控制层,再由控制层也就是(servlet)返回给页面,页面接收就可以了.
      

  4.   

    public ResultSet branch() {
      String sql="select branch_no,branch_name from branch";
      try{
      conn = DriverManager.getConnection(url);
      PreparedStatement ps = conn.prepareStatement(sql);
      ResultSet res = ps.executeQuery();  
      return res;
      }
      catch(Exception e){
      return null;
      }
      }在jsp网页中直接用下面这种方也能接收呀?
    ResultSet RS = workM.executeQuery(workM.branch());
    while (RS.next()) {
        String branch_no=RS.getString(1);
        String branch_name=RS.getString(2);
          }
    }  
    RS.close();
      

  5.   

    JSP中可以这样获取
    ResultSet RS = workM.branch();
    while (RS.next()) {
        String branch_no=RS.getString(1);
        String branch_name=RS.getString(2);
      }
    }   
    RS.close();
      

  6.   

    jsp中sql标签可以直接连数据库。
      

  7.   

    JSP中可以这样获取
    <%
    ResultSet RS = workM.branch();
    while (RS.next()) {
        String branch_no=RS.getString(1);
            Out.println(branch_no);
        String branch_name=RS.getString(2);
            Out.println(branch_name);
      }
    }  
    RS.close();
    %>