简体   繁体   中英

How to call a MSSQL stored procedure using java

i had few doubts which need clarification. Please help me to get through

i had a stored procedure in my MSSQL Server and i need to call it from java, as per my knowledge i need to perform these steps to call the procedure

  1. connect to the database(exact location where the procedure is stored)
  2. call the procedure using callablestatement CallableStatement cstmt = con.prepareCall("{call getEmployeeDetails(?, ?)}");

Know please give me examples on how to use callablestatement and also how to pass parameters to procedures using java.

/ After Establishing the connection to MSSQL database, here goes the code how to call a stored procedure /

 Connection conn;
 CallableStatement stmt = conn.prepareCall("{call dbo.usp_scr_getAllFiles()}");
 stmt = conn.prepareCall("{call dbo.usp_scr_startLoading()}");   
 stmt.close();
 conn.close();

/ In the above code i called two stored procedures /

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM