Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.databases > #308
| From | "Starbuck" <starbuck@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: java and ms-server |
| Message-ID | <fs0Nk.14132$pf1.8842@newsfe27.ams2> (permalink) |
| Newsgroups | comp.lang.java.databases |
| References | <490488fd$0$90271$14726298@news.sunsite.dk> |
| Date | 2011-04-27 15:22 +0000 |
| Organization | TDS.net |
To: comp.lang.java.databases
Arne Vajhoj wrote:
> Starbuck wrote:
>> New to the group to sorry if this has been asked before.
>> I am learniing Java at Uni and so far I have connected to a MS Server
>> and I have read data ok. Now I want to connect to the stored
>> procedures already in place.
>>
>> Below is a procedure in question -
>> CREATE PROCEDURE record_count
>> (
>> @cnt int OUTPUT
>> )
>> AS
>> BEGIN
>> /* Procedure body */
>> SELECT @cnt = count(8)
>> From curry
>> END
>>
>> Nice and easy returns number of records in table.
>> Here is my working c# code
>>
>> public int recCount()
>> {
>> try
>> {
>> openCon();
>> //not sure from here peeps SqlCommand cmd = new
>> SqlCommand("record_count", con);
>> cmd.CommandType = CommandType.StoredProcedure;
>> SqlParameter countParameter = new SqlParameter("@cnt", 0);
>> countParameter.Direction = ParameterDirection.Output;
>> cmd.Parameters.Add(countParameter);
>> cmd.ExecuteNonQuery();
>> int rc =
>> Int32.Parse(cmd.Parameters["@cnt"].Value.ToString());
>> if (con.State == ConnectionState.Open) con.Close();
>> return rc;
>> }
>> catch (Exception ex)
>> {
>> string exx = ex.Message ;
>> return 0;
>> }
>> }
>>
>> Can anyone point me in the correct direction for the Java method please.
>> Many thankings in advance.
>
> It should be something like:
>
> CallableStatement cstmt = con.prepareCall("{CALL record_count(?)}");
> cstmt.registerOutParameter(1, Types.INTEGER);
> cstmt.execute();
> int rc = cstmt.getInt(1);
>
> Arne
Arne
That is brill, many thanks
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.databases | Previous | Next — Previous in thread | Next in thread | Find similar
java and ms-server "Starbuck" <starbuck@THRWHITE.remove-dii-this> - 2011-04-27 15:22 +0000
Re: java and ms-server "=?ISO-8859-1?Q?Arne_Vajh=" <=?iso-8859-1?q?arne_vajh=@THRWHITE.remove-dii-this> - 2011-04-27 15:22 +0000
Re: java and ms-server "Starbuck" <starbuck@THRWHITE.remove-dii-this> - 2011-04-27 15:22 +0000
Re: java and ms-server "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: java and ms-server "David Harper" <david.harper@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: java and ms-server "Starbuck" <starbuck@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: java and ms-server "John W Kennedy" <john.w.kennedy@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: java and ms-server "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
Re: java and ms-server "Martin Gregorie" <martin.gregorie@THRWHITE.remove-dii-this> - 2011-04-27 15:23 +0000
csiph-web