Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 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 javaappclienttodbase; // package is named by the project name
  7.  
  8. //import java.sql.Connection;
  9. //import java.sql.DriverManager;
  10. //import java.sql.ResultSet;
  11. //import java.sql.SQLException;
  12. //import java.sql.Statement;
  13. import java.sql.*;
  14. import java.util.Enumeration;
  15. import javax.swing.JOptionPane;
  16.  
  17. public class JavaAppClientToDbase
  18. {
  19.  
  20. public static void main(String[] args) throws ClassNotFoundException, SQLException
  21. {
  22. //
  23. // --------------- Connection to the postgres dbase -------------------
  24.  
  25.  
  26. //String sourceURL = "jdbc:postgresql://localhost:5432/BookShop [postgres on cis5202]";
  27. String sourceURL = "jdbc:postgresql://localhost:5432/BookShop";
  28. Connection con = DriverManager.getConnection(sourceURL,"postgres","root");
  29.  
  30. // ----------------Creation of the Statement object ---------------
  31. Statement stmt = con.createStatement();
  32. String QueryString = "SELECT * FROM cis5202.book";
  33.  
  34. // ---------------- Execution of query showing all book records as objects
  35. ResultSet results = stmt.executeQuery(QueryString);
  36. while (results.next())
  37. {
  38. System.out.println(results.getString(1));
  39. System.out.println(results.getString(2));
  40. System.out.println(results.getString(3));
  41. System.out.println(results.getString(4));
  42. }
  43.  
  44.  
  45. } // end main()
  46. } // end of JavaAppClientToDbase class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement