Reputation: 313
I'm trying to call a stored procedure from Java code. Procedure is working fine in DB2 but when I apply it with Spring and run java code, it is not inserting the record for which I wrote logic in stored proc.
Stored procedure code in DB2:
CREATE PROCEDURE MFAA.sample_pal(
IN Stmt varchar(2048)
)
LANGUAGE SQL
BEGIN
-- declare Stmt varchar(2048);
-- set Stmt = 'PALLAVI';
-- print Stmt;
-- select Stmt;
--DBMS_OUTPUT.PUT_LINE('Value : '||Stmt);
insert into MFAA.DUMMYTABLE values(Stmt);
return 0;
END
java code:
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import java.util.*;
public class callprocedure {
private JdbcTemplate jdbctemplate;
private SimpleJdbcCall jdbcCall;
public JdbcTemplate getJdbctemplate() {
ApplicationContext cx=new ClassPathXmlApplicationContext("db2Context.xml");
this.jdbctemplate=(JdbcTemplate) cx.getBean("jdbcTempDB2");
return jdbctemplate;
}
public void setJdbctemplate(JdbcTemplate jdbctemplate) {
this.jdbctemplate = jdbctemplate;
//this.jdbcCall= new SimpleJdbcCall(jdbctemplate).withProcedureName("sample_pal");
}
public static void main(String[] args) {
String name="Pradeep";
try
{
JdbcTemplate jt=new DbConnection().getJdbctemplate();
System.out.println("CALL STORED PROCEDURES");
int rs=jt.update("call sample_pal(?)",name);
System.out.println("Result : "+rs);
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Upvotes: 1
Views: 6539
Reputation: 313
In java code which has been shared we need to call the procedure with schema_name.proceure_name() then it works. So in the piece of code which is shared just change int rs=jt.update("call sample.sample_pal(?)",name);
where sample
is the schema name and sample_pal
is the procedure name
Upvotes: 1