Abdullah047

Stored_Procedure_ResultSet_SQL

Sep 2nd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package sqltest;
  7.  
  8. import java.sql.CallableStatement;
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.ResultSet;
  12. import java.sql.SQLException;
  13.  
  14. /**
  15.  *
  16.  * @author Abdullah
  17.  */
  18. public class Stored_procedure_ResultSet {
  19.      public static void main(String[] ags) throws SQLException{
  20.     String  URL="jdbc:mysql://localhost:3306/demo?autoReconnnect&useSSL=false";
  21.     String user="root";
  22.     String password="abdullah";
  23.     String SQL=
  24.             "{  call  get_employees_for_department(?) } "
  25.             ;
  26.     String Department="Legal";
  27.     Connection connect=DriverManager.getConnection(URL,user,password);
  28.     CallableStatement CS=connect.prepareCall(SQL);
  29.     CS.setString(1, Department);
  30.     CS.execute();
  31.     ResultSet result=CS.getResultSet();
  32.     Display(result);
  33.    
  34.     }  
  35.      public static void Display(ResultSet result) throws SQLException{
  36.      while(result.next()){
  37.       System.out.println(result.getString(1)+"\t"+result.getString(2)+"\t"+result.getString(3)+"\t"
  38.               +result.getString(4)+"\t"+result.getString(5)+"\t"+result.getString(6)+"\t"
  39.       +result.getString(7)+"\t"
  40.       ) ;                        
  41.      
  42.      
  43.      }
  44.          }
  45.          
  46. }
Add Comment
Please, Sign In to add comment