1 import java.sql.*;
2
3 public class TestCallableStatement {
4
5 public static void main(String[] args) throws Exception {
6 Class.forName("com.mysql.jdbc.Driver");
7 Connection connection = DriverManager.getConnection(
8 "jdbc:mysql://localhost/javabook", "scott", "tiger");
9
10
11
12
13
14
15 CallableStatement callableStatement = connection.prepareCall(
16 "{? = call studentFound(?, ?)}");
17
18 java.util.Scanner input = new java.util.Scanner(System.in);
19 System.out.print("Enter student's first name: ");
20 String firstName = input.nextLine();
21 System.out.print("Enter student's last name: ");
22 String lastName = input.nextLine();
23
24 callableStatement.setString(2, firstName);
25 callableStatement.setString(3, lastName);
26 callableStatement.registerOutParameter(1, Types.INTEGER);
27 callableStatement.execute();
28
29 if (callableStatement.getInt(1) >= 1)
30 System.out.println(firstName + " " + lastName +
31 " is in the database");
32 else
33 System.out.println(firstName + " " + lastName +
34 " is not in the database");
35 }
36 }