Abdullah047

OUT_SQL

Sep 2nd, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 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.SQLException;
  12. import java.sql.*;
  13. /**
  14.  *
  15.  * @author Abdullah
  16.  */
  17. public class OUT {
  18.     public static void main(String[] args) throws SQLException{
  19.         String url="jdbc:mysql://localhost:3306/demo?autoReconnect&useSSL=false";
  20.         String user="root";
  21.         String password="abdullah";              
  22.         String SQL=
  23. "{  call get_count_for_department(?,?)  }"
  24.                 ;
  25.         String Department ="HR";
  26.         Connection connect=DriverManager.getConnection(url, user,password);
  27.    
  28.    CallableStatement CS=connect.prepareCall(SQL);
  29.     CS.setString(1,Department);
  30.     CS.registerOutParameter(2, Types.INTEGER);
  31.     CS.execute();
  32.    
  33.     int Result=CS.getInt(2)  ;
  34.     System.out.println("Result="+Result);
  35.     }
  36. }
Add Comment
Please, Sign In to add comment