简体   繁体   中英

Calling stored procedure from java code using hibernate/jdbc with list of values/objects as parameter

Is there a way to call a stored procedure created on SQL server via java code using hibernate/jdbc with passing list of values/objects as parameters? If yes then how can i achieve it? I know how to call a stored procedure, but i have used stored procedures so far with passing only few parameters and not a complete list of values as i intend to do batch update/insert. If i do something like the following, would that make sense?

getTemplate().getSessionFactory().getCurrentSession().createSQLQuery("CALL proc_insert(:list)").setParameterList("list", objList).executeUpdate();

this may help Use callableStatement

String getDBUSERByUserIdSql = "{call getDBUSERByUserId(?,?,?,?)}";
callableStatement = dbConnection.prepareCall(getDBUSERByUserIdSql);
callableStatement.setInt(1, 10);
callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
callableStatement.registerOutParameter(3, java.sql.Types.VARCHAR);
callableStatement.registerOutParameter(4, java.sql.Types.DATE);

// execute getDBUSERByUserId store procedure
callableStatement.executeUpdate();

String userName = callableStatement.getString(2);
String createdBy = callableStatement.getString(3);
Date createdDate = callableStatement.getDate(4);

For more Info click

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