/*
** Demonstrates code to get information from the user.
*/
import java.sql.*;

public class DBDemo3
{
  public static void main(String args[]) 
    throws ClassNotFoundException,SQLException
  {
    String database="demo_db";
    String url="jdbc:postgresql://csci.hsutx.edu/"+database;
    String username="demo";
    String password="welovethisclass";
    Connection con;
    Statement stmt;
    ResultSet result;

    Class.forName("org.postgresql.Driver");   // load the driver
    System.out.print("Driver Loaded Successfully!\n");
    con= DriverManager.getConnection(url,username,password);
    System.out.print("Connection to database'"+database+"' established.\n");

    stmt= con.createStatement();
    stmt.executeUpdate("set search_path to albumdb");

    result= stmt.executeQuery("select * from artist");
    while (result.next()) {
      System.out.println(result.getString("id"));   // field name notation
      System.out.println(result.getString("name"));
      System.out.println(result.getString(3));      // positional notation
      System.out.println();
    }
    con.close();  // close connection to username
  }
}

