ajanuskevicius
8/16/2016 - 2:34 PM

Java - JDBC - callOutStoredProcedure

Java - JDBC - callOutStoredProcedure

public void callOutStoredProcedure () throws SQLException {
		
		try (
				
				Connection conn = DB_Util.getConn(DB_Types.MYSQLDB);
				CallableStatement callStat = conn.prepareCall("{ call getPopulationByContinent(?, ?) }");
				Scanner scanner = new Scanner(System.in);
				)		
		{
			
			System.out.print("Enter Continent Name: ");
			callStat.setString(1, scanner.nextLine());
			
			callStat.registerOutParameter(2, Types.INTEGER);
			
			callStat.execute();
			
			long totalPop = callStat.getLong(2);
			
			System.out.println("Total Population is: " + totalPop);
		}
		catch(SQLException ex) {
			
			DB_Util.getErrorMessage(ex);
		}
	}