Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 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 Connection connect() throws SQLException {
  15. return DriverManager.getConnection(url, user, password);
  16. }
  17. public void callPro(int id) {
  18. int inv_id = id;
  19. int cust_id = 0;
  20. String name = "";
  21. try {
  22. Connection conn = connect();
  23. CallableStatement cstmt = conn.prepareCall("{? = call print_full_name(?)}");
  24. cstmt.setInt(2, inv_id);
  25. cstmt.registerOutParameter(1, Types.VARCHAR);
  26. cstmt.execute();
  27. name = cstmt.getString(1);
  28. System.out.println(name);
  29. }catch (SQLException e) {
  30. System.out.println(e.getMessage());
  31. }
  32. }
  33. public TestJava() {
  34. // TODO Auto-generated constructor stub
  35. }
  36. public static void main(String[] args) {
  37. // TODO Auto-generated method stub
  38. TestJava t = new TestJava();
  39. t.callPro(1);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement