import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Example { public static void main(String[] args) throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "root"); CallableStatement callableStatement = connection.prepareCall("{call getAge(?, ?)}"); callableStatement.setString(1, "John"); callableStatement.registerOutParameter(2, java.sql.Types.INTEGER); callableStatement.execute(); int age = callableStatement.getInt(2); System.out.println("Age: " + age); callableStatement.close(); connection.close(); } }
import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Example { public static void main(String[] args) throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "root"); CallableStatement callableStatement = connection.prepareCall("{? = call getSalary('John')}"); callableStatement.registerOutParameter(1, java.sql.Types.INTEGER); callableStatement.execute(); int salary = callableStatement.getInt(1); System.out.println("Salary: " + salary); callableStatement.close(); connection.close(); } }These examples use the java.sql package library.