/* This program demonstrates the use of a CallableStatement It calls the "example3" stored procedure found in the test database. example3() is created by executing the ex3.sql file. */ import java.sql.*; public class Callable { public static void main(String[] args) { // Connect to the database // You can put a database name before the ? in the connection URL. Connection conn = null; String url = "jdbc:mysql://sql.cs.oberlin.edu/test?"; String parms = "user=alice&password=tiger&useSSL=false"; try { conn = DriverManager.getConnection(url+parms); // Create a PreparedStatement CallableStatement stmt = conn.prepareCall("call example3()"); // Select data from the MOVIE table boolean hasRS = stmt.execute(); while(hasRS || stmt.getMoreResults()){ try (ResultSet rs = stmt.getResultSet()){ if(rs.next()) { System.out.println(rs.getString(1)); } } hasRS = false; } // close the connection if (conn != null) conn.close(); } catch(SQLException e) { e.printStackTrace(); } catch(Exception ee){ ee.printStackTrace(); } } }