Guest User

Untitled

a guest
Nov 2nd, 2018
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.sql.CallableStatement;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Types;
  7. import javax.xml.transform.Result;
  8.  
  9. public class TestJava {
  10.     private final String url = "jdbc:postgresql://localhost:5433/dvdrental";
  11.     private final String user = "postgres";
  12.     private final String password = "makary123";
  13.  
  14.     public static void main(String[] args) {
  15.     // TODO Auto-generated method stub
  16.         callProcedure();
  17.     }
  18.  
  19.     public Connection connect() throws SQLException {
  20.         return DriverManager.getConnection(url, user, password);
  21.     }
  22.  
  23.     public void callProcedure() {
  24.         try {
  25.             Connection conn = connect();
  26.             CallableStatement cstmt = conn.prepareCall("{? = call print_full_name(?)}");
  27.             cstmt.setInt(2, 1);
  28.             cstmt.registerOutParameter(1, Types.VARCHAR);
  29.             cstmt.execute();
  30.             String name = cstmt.getString(1);
  31.             System.out.println(name);
  32.         }
  33.         catch (SQLException e) {
  34.             System.out.println(e.getMessage());
  35.         }
  36.     }
  37. }
Add Comment
Please, Sign In to add comment