Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaappclienttodbase; // package is named by the project name
- //import java.sql.Connection;
- //import java.sql.DriverManager;
- //import java.sql.ResultSet;
- //import java.sql.SQLException;
- //import java.sql.Statement;
- import java.sql.*;
- import java.util.Enumeration;
- import javax.swing.JOptionPane;
- public class JavaAppClientToDbase
- {
- public static void main(String[] args) throws ClassNotFoundException, SQLException
- {
- //
- // --------------- Connection to the postgres dbase -------------------
- //String sourceURL = "jdbc:postgresql://localhost:5432/BookShop [postgres on cis5202]";
- String sourceURL = "jdbc:postgresql://localhost:5432/BookShop";
- Connection con = DriverManager.getConnection(sourceURL,"postgres","root");
- // ----------------Creation of the Statement object ---------------
- Statement stmt = con.createStatement();
- String QueryString = "SELECT * FROM cis5202.book";
- // ---------------- Execution of query showing all book records as objects
- ResultSet results = stmt.executeQuery(QueryString);
- while (results.next())
- {
- System.out.println(results.getString(1));
- System.out.println(results.getString(2));
- System.out.println(results.getString(3));
- System.out.println(results.getString(4));
- }
- } // end main()
- } // end of JavaAppClientToDbase class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement