Link to home
Create AccountLog in
Avatar of searchsanjaysharma
searchsanjaysharma

asked on

How to call a procedure in Java.

How to call a procedure in java/
How to test whether a connection is open or closed.
Avatar of MrC63
MrC63
Flag of Canada image

This is a bit obscure, can you elaborate further?  

- What type of connection are you attempting to test to see if it's open or closed.  
- Are you trying to do this with a Java applet, or with JavaScript in an HTML page?
Avatar of searchsanjaysharma
searchsanjaysharma

ASKER

I am sending the example in dot net.
I want to check whether the connection is closed, if so then only open it.
Secondly how to call a procedure.
Try
            con = New SqlConnection("Data Source=192.168.171.41;Initial Catalog=amis;User Id=sa;Password=XXXX")
            cmd = New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = con
            cmd.CommandText = "saveuser"
            If con.State = ConnectionState.Open Then con.Close()
            con.Open()
            cmd.Parameters.AddWithValue("@username", txtusername.Text.Trim())
            cmd.Parameters.AddWithValue("@password", txtpassword.Text.Trim())
            cmd.ExecuteNonQuery()
            MessageBox.Show("Record Saved Sucessfully")
        Catch eee As Exception
            MessageBox.Show("Error occured" & eee.ToString())
        Finally
            con.Close()
        End Try
ASKER CERTIFIED SOLUTION
Avatar of Valeri
Valeri
Flag of Bulgaria image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account