Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

what does these errors mean? I am trying to create a program that has log in verification, user registration, books selection, adding new books and

what does these errors mean? I am trying to create a program that has log in verification, user registration, books selection, adding new books and deleting new books to the database from a java program.

here is the errors:

org.postgresql.util.PSQLException: FATAL: database "cooper" does not exist at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:730) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:231) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:67) at org.postgresql.jdbc.PgConnection.(PgConnection.java:212) at org.postgresql.Driver.makeConnection(Driver.java:407) at org.postgresql.Driver.connect(Driver.java:275) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at DBConnection.(DBConnection.java:46) at cooperbooks.getConnected(cooperbooks.java:64) at cooperbooks.(cooperbooks.java:39) at cooperbooks.main(cooperbooks.java:28) Exception in thread "main" java.lang.NullPointerException at cooperbooks.loginUser(cooperbooks.java:72) at cooperbooks.getStarted(cooperbooks.java:50) at cooperbooks.main(cooperbooks.java:29) here is my code:

import java.sql.*; import java.io.*; import java.util.*;

public class cooperbooks { private Connection connection = null; private DBConnection jdbc; private ResultSet result; private int option; private String login; private Scanner input;

private static final int MAX = 3;

static public void main(String args[]) throws IOException, SQLException { cooperbooks one;

one = new cooperbooks(); one.getStarted(); } // main method

/** default constructor */ public cooperbooks() throws IOException, SQLException { input = new Scanner(System.in); getConnected(); }

/** attempts to connect to the database; processes query once it is connected; displays the results */ public void getStarted() throws IOException, SQLException {

{ loginUser(); registerUser(); displayMenu(); //getOption(); // takeAction(); } } // method getStarted

/** attempts to connect to the database */ public void getConnected() throws IOException { jdbc = new DBConnection(); connection = jdbc.getConnection(); } // method getConnected

public void loginUser() throws SQLException { String sql; int count =0; Statement select = connection.createStatement(); sql = "SELECT " + "user_name, hashed_password " + "FROM " + "member"; System.out.println(sql); result = select.executeQuery(sql); String user_name=null; String hashed_password=null; String username; String password; boolean yes=false; int login=0; while(result.next()) { user_name = result.getString(5); if (result.wasNull()) { user_name = null; } //if

hashed_password = result.getString(4);

if (result.wasNull()) { hashed_password = null; } } while(login!= MAX) {

System.out.println("Enter Username"); username=input.nextLine(); System.out.println ("Enter password"); password = input.nextLine(); if((username.equals(user_name)) && password.equals(hashed_password)) { System.out.println("Welcome Member"); System.out.println("Select option"); displayMenu();

} else { System.out.println("Log is invalid"); System.out.println(" do want to be a member, Yes or No ?"); yes=input.nextBoolean(); } if (yes==true) { registerUser(); } else { System.out.println("Enter Username"); username=input.nextLine(); System.out.println ("Enter password"); password=input.nextLine(); } } } public void registerUser() throws SQLException {

String last_name; String first_name; String email; String user_name; String hashed_password; String street; String city; String state; int zip; String card_type; int card_no; String expiration; String name_on_card; System.out.println("Enter your last name"); last_name= input.nextLine(); System.out.println("Enter your first name"); first_name=input.nextLine(); System.out.println("Enter your email"); email=input.nextLine(); System.out.println("Enter your password"); hashed_password= input.nextLine(); System.out.println("Enter your username"); user_name=input.nextLine(); System.out.println("Enter your street"); street=input.nextLine(); System.out.println("Enter your city"); city= input.nextLine(); System.out.println("Enter state with 2 letter format"); state=input.nextLine(); System.out.println("Enter your five digit zip"); zip=input.nextInt(); System.out.println("Enter your card_type"); card_type= input.nextLine(); System.out.println("Enter your 16 digit card no"); card_no=input.nextInt(); System.out.println("Enter your expiration "); expiration=input.nextLine(); System.out.println("Enter your name_on_card"); name_on_card = input.nextLine();

Statement insert = connection.createStatement(); String sql= "Insert into" +"last_name,first_name,email,hashed_password,user,street,city,state, zip, card_type, card_no, expiration, name_on_card"; result = insert.executeQuery(sql);

} public void displayMenu() { System.out.println("\t\t\tCooper Online Book Store"); System.out.println();

System.out.println("1. Search for Books By ISBN"); System.out.println("2. Search for Books By Author"); System.out.println("3. Search for Books By Title"); System.out.println("4. Search for Books by Keywords"); System.out.println("5. Show Shopping Cart or Remove Book Entries from Shopping Cart"); System.out.println("6. Submit Order"); System.out.println("7. Post Books for Sales"); System.out.println("8. Remove Books from Sales"); System.out.println("9. End of Application"); System.out.println(); System.out.print("Enter your choice ==> "); } // method displayMenu

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions