Jianhong,
If you are using execute() as the method to actually execute the sql string (as
opposed to executeQuery()) then you have to make a getResultSet() call to (yep
you guessed it!) get a result set. Once you have a result set it is necessary
to call the next() method to move too the first row and then your getString to
obtain the actual data ( I use getObject actually as it is more versatile) .
Make more calls to next () as required to retrieve other rows
mail again if this doesn't sort it out.
rgds
Jianhong wrote:
> Hi,
>
> Thanks for all your response. I know callable statement should be used, but
> I don't know how to execute and get result from it. The following is the
> code:
>
> CallableStatement cs = m_con.prepareCall("{call proc_1 (?, ?, ?)}");
> System.out.println("Setting parameters...");
> cs.setInt(1, 11);
> cs.setInt(2, 12);
> cs.registerOutParameter(3, java.sql.Types.LONGVARCHAR);
> System.out.println("Executing query...");
> cs.execute();
> System.out.println("Displaying result...");
> System.out.println("Result: " + cs.getString(3));
> cs.close();
>
> There is no error, but no result displayed.
>
> Thanks in advance.
>
> Jianhong
>
> ----- Original Message -----
> From: Tim Stephenson <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, January 17, 2000 9:59 PM
> Subject: Re: Pls. help[off topic]
>
> > Jianhong,
> >
> > The mechanism for executing stored procs in java is a callable statment.
> At
> > the most basic level you need to :
> > 1. get a connection (I assume you have this, from your comment about the
> ODBC
> > bridge)
> > 2. create a callable statement from the connection using the DBMS
> independent
> > calling pseudocode
> > e.g.cs = conn.prepareCall ( {call (?, ?, ? ) } ; // 3 ? one for each
> of
> > your parameters
> > 3. specify the parameters (if any)
> > e.g. cs.setInt (1, x) ; // where x is your integer value for
> parameter
> 1
> > file://another setInt
> > // a setString
> > 4. call the statement
> > e.g. cs.executeQuery // or executeUpdate as appropriate
> >
> > Hope this helps,
> >
> > The sun tutorial for JDBC is pretty good as a starter, also the api docs
> > ellaborate on the callable statement class.
> >
> > Jianhong wrote:
> >
> > > Hi,
> > >
> > > I have a stored procedure, but I don't know how to run and get
> > > result from it using JDBC-ODBC bridge. The following is the
> > > procedure, any help would be very appreciated.
> > >
> > > create procedure proc_1
> > > (@siteID int, @catID int, @result char(200) output) as
> > > select @result = siteURL from classifiedSite
> > > where siteID = @siteID and catID = @catID
> > >
> > > Jianhong
> > >
> > > - att1.htm
> > >
> >
> ------------------------------------------------------------------------
> > > Name: att1.htm
> > > att1.htm Type: Hypertext Markup Language (text/html)
> > > Encoding: quoted-printable
> >
> > --
> > Tim Stephenson
> > -----------------------------------------------------------
> > e: [EMAIL PROTECTED] or [EMAIL PROTECTED]
> > m: +44 7775 66 00 58
> > h: +44 207 254 5196
> > v: +44 1628 597279
> > -----------------------------------------------------------
> >
> >
> ___________________________________________________________________________
> > 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
>
> ___________________________________________________________________________
> 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
--
Tim Stephenson
-----------------------------------------------------------
e: [EMAIL PROTECTED] or [EMAIL PROTECTED]
m: +44 7775 66 00 58
h: +44 207 254 5196
v: +44 1628 597279
-----------------------------------------------------------
___________________________________________________________________________
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