Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ziaulh,

i want ask about stored procedure that no return data on sql server on hibernate...

i made this but not work

C#
Session session = service.getDataServiceManager().getSession();
   try {
       Object result1 =
       session.createSQLQuery("exec dbo.insert_users '"+useramerica+"','"+usereuropa+"'");
       service.commit();

      } catch (Exception ex) {
          ex.printStackTrace();
          service.rollback();
      }


im use java you think i miss something?

Manuel Rodriguez Coria
[Email removed]
Tarija, Bolivia
Posted
Updated 5-Sep-10 7:26am
v2
Comments
Sandeep Mewara 5-Sep-10 13:28pm    
You asked this question to someone specific, not sure if it's related to some article or what. If so, use the message forum available at the bottom of the article.

Further, no need to provide your email id. It would just attract spam. Once someone answers you, an email will be dropped to your account automatically.
Manuel Rodriguez Coria 5-Sep-10 13:36pm    
ok sorry thanks for the clarification

The way you are calling the stored procedure with the parameter is not good practice, You should use SqlCommand and SqlParameter as well. For example:
C#
using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();
 
    SqlCommand command= new SqlCommand("StoredProcedure name", Conn);
                command.CommandType = CommandType.StoredProcedure;
        //
        // Add new SqlParameter to the command.
        //
        command.Parameters.Add(new SqlParameter("Name", dogName));
        // Also can be used to add sqlparam like
        // command.Parameters.AddWithValue(new SqlParameter("Name", dogName));
        //
        // Read in the SELECT results.
        //
        SqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {

        }
}
 
Share this answer
 
v2
Comments
Аslam Iqbal 8-Mar-11 16:09pm    
very simple. I like it my 5
[no name] 8-Mar-11 23:51pm    
Thanks
i found the solution thanks any way
Session session = service.getDataServiceManager().getSession();<br />
       <br />
     try{<br />
     //call stored procedure<br />
     String sqlcmd = "{call dbo.insert_users( ?, ?)}";<br />
     Connection conn = session.connection();<br />
     //adding connection to callablestatement<br />
     CallableStatement cs = conn.prepareCall( sqlcmd);<br />
     //fill psrameters for calablestatment<br />
     cs.setString(1, useramerica);<br />
     cs.setString(2, usereuropa);<br />
     cs.execute();<br />
     cs.close();<br />
     service.commit();<br />
     } catch ( SQLException e) {<br />
           e.printStackTrace();<br />
     }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900