如何在两个方法之间传递参数public void  getseq() throws SQLException {
Connection conn = DBAccess.getInstance().getConnection();
PreparedStatement pstm = null;
PreparedStatement pstm1= null;


try {
pstm = conn.prepareStatement("selcet seq.nextval from XW ");
pstm1 = conn.prepareStatement("selcet seq.nextval from XW_FJ ");
 

 ResultSet rs =   pstm.executeQuery();
 int a  = rs.getInt(1);
 int b = rs.getInt(2);














}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();






}









}

public void insertXW(int  a ,int  b){。要把前一个方法的两个值给下一个方法。

解决方案 »

  1.   

    try { 
    pstm = conn.prepareStatement("selcet seq.nextval from XW "); 
    pstm1 = conn.prepareStatement("selcet seq.nextval from XW_FJ "); 
       ResultSet rs =   pstm.executeQuery(); 
     int a  = rs.getInt(1); 
     int b = rs.getInt(2); 
    insertXW(a,b)}catch (SQLException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
      

  2.   

    将a,b定义为全局变量;
    int a = 0;
    int b = 0;

    public void  getseq() throws SQLException { 
    Connection conn = DBAccess.getInstance().getConnection(); 
    PreparedStatement pstm = null; 
    PreparedStatement pstm1= null; 
    try { 
    pstm = conn.prepareStatement("selcet seq.nextval from XW "); 
    pstm1 = conn.prepareStatement("selcet seq.nextval from XW_FJ "); 
       ResultSet rs =   pstm.executeQuery(); 
     a  = rs.getInt(1); 
     b = rs.getInt(2); 
    }catch (SQLException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); } } public void insertXW(int  a ,int  b){ 
    。 
      

  3.   

    将a,b定义为全局变量; 
    int a = 0; 
    int b = 0; 
      

  4.   

    也可以把a,b封装到一个对象bean里。省事
      

  5.   

    第一个方法可以返回list
     list.add(a);
     list.add(b);return list;
      

  6.   

    这个方法不错,把getSeq()方法返回的所有值放进List容器,当然要申请。
      
    下面是我改写后的程序import java.util.List;public List<int>   getseq() throws SQLException {
    Connection conn = DBAccess.getInstance().getConnection();
    PreparedStatement pstm = null;
    PreparedStatement pstm1= null;
    try {
    pstm = conn.prepareStatement("selcet seq.nextval from XW ");
    pstm1 = conn.prepareStatement("selcet seq.nextval from XW_FJ ");
      ResultSet rs =   pstm.executeQuery();
     int a  = rs.getInt(1);
     int b = rs.getInt(2);
     
     List<int> list=new List<int>();
     list.add(a);
     list.add(b);
     return list;}catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }public void insertXW(int  a ,int  b){
        
    }