Hi!

I'm working with servlets towards an Sybase System 11 Database, and I'm trying to call 
a stored procedure that may return mulitple rows. As I've understood (read from the 
archive) I should use a "CallableStatement" like this:
cstmt = conn.prepareCall("{ ? = call p_WEB(?, ?, ?, ?)}") ;
where the first ? is the resultset. Should this be registered as an outparameter? What 
kind of type is it? I've seen code like: 
cstmt.registerOutParameter(1,OracleTypes.CURSOR);
Can I use some of the constants in java.sql.Types, or is there an "SybaseTypes" class??
I've used prepareStatement, is this not the way to go if the procedure returns 
multiple rows??

Could someone please give me a complete example??

Also some of my in-parameters to the stored procedure are varchar and some are char, 
which gave me some trouble. Can someone confirm that my code is correct. All comments 
are most welcome.

Regards,
Mette

...
Here is my code with prepareStatement:

     Vector ret = new Vector();
     ResultSet rs = null;
     PreparedStatement pstmt=null;

         pstmt=conn.prepareStatement("exec p_WEB 
@tjeneste=?,@kategori=?,@applikasjon=?,@tlfnr=?,@kommune=?,@veikode=?,         
@veinavn=?,@husnr=?,@husbokstav=?,@etasje=?,@leilighet=?");

        //char
       if( tjeneste!=null && tjeneste!="" )
       {
         pstmt.setString(1,tjeneste);
       }
       else
       {
         pstmt.setNull(1,java.sql.Types.CHAR);
       }
        ...
        //testing the same way for some more parameters
        ...
        //varchar
       if( veinavn!=null && veinavn!="" )
       {
         pstmt.setString(7,veinavn);
       }
       else
       {
         pstmt.setNull(7,java.sql.Types.VARCHAR);
       }
        ...
        //testing the same way for some more parameters
        ...

       rs = pstmt.executeQuery();

          SvarInfo svarInfo=null;
          while(rs.next())
       {
         svarInfo = new SvarInfo(((Integer)rs.getObject("resultatkode")),
                                 ((String)rs.getObject("resultat")),
                                 
(((String)rs.getObject("merknader1"))+((String)rs.getObject("merknader2"))+((String)rs.getObject("merknader3"))),
                                 ((String)rs.getObject("nrfslsign")),
                                 ((String)rs.getObject("as_lfslsign")),
                                 ((String)rs.getObject("utstyrfslsign")),
                                 ((String)rs.getObject("gslsignatur")),
                                 ((String)rs.getObject("modersign")),
                                 ((String)rs.getObject("linjenr")),
                                 ((String)rs.getObject("telsisid")),
                                 ((String)rs.getObject("leveringsdato")),
                                 ((String)rs.getObject("akstype")),
                                 ((Integer)rs.getObject("komnr")),
                                 ((String)rs.getObject("veikode")),
                                 ((String)rs.getObject("veinavn")),
                                 ((Integer)rs.getObject("husnr")),
                                 ((String)rs.getObject("husbokstav")),
                                 ((String)rs.getObject("etasje")),
                                 ((String)rs.getObject("leilighetsnr")),
                                 ((Integer)rs.getObject("tot_ant")));

            ret.addElement(svarInfo);
          }
          pstmt.close();
          rs.close();
        }
     catch (SQLException e)
     {
             e.printStackTrace();
        }

     return ret;
   }

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to