How to call database function from java

Published on Author bloggerfiveLeave a comment

Remember database  function can return values but stored procedure can’t .

The following code snippet will clearly guide how to call mysql function which has three params with return type .

Aim – The java code retrives voterId from Voterlist function with given voterName ,voterAge and Address params,


               CallableStatement cStmt = connection.prepareCall(“{? = call voterList(?,?,?,?)}”);
                cStmt.setString(2, voterName);
                cStmt.setString(3, voterAge);
                cStmt.setString(4, Address);
                int voterId = cStmt.getInt(1);





Leave a Reply

Your email address will not be published. Required fields are marked *