Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7811699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:15:54+00:00 2026-06-02T04:15:54+00:00

Currently trying to insert an object into the Customer table using a test SQL

  • 0

Currently trying to insert an object into the Customer table using a test SQL run. However, everything I run the test, the compiler returns the following exception:

Exception in thread "main" java.lang.RuntimeException: error finding Customer
    at edu.depauw.csc480.dao.CustomerDAO.find(CustomerDAO.java:78)
    at edu.depauw.csc480.dao.CustomerDAO.insert(CustomerDAO.java:87)
    at edu.depauw.csc480.dao.DatabaseManager.insertCustomer(DatabaseManager.java:84)
    at edu.depauw.csc480.Test.main(Test.java:18)
Caused by: java.sql.SQLSyntaxErrorException: Table/View 'CUSTOMER' does not exist.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)

I have looked at the code over and over again, however, I can’t seem to find an error as it compiles fine, just doesn’t run. Below is my create method & find method from my CustomerDAO class.

public Customer find(int custID) {
        if (cache.containsKey(custID)) return cache.get(custID);

        try {
            String qry = "select name from CUSTOMER where custID = ?";
            PreparedStatement pstmt = conn.prepareStatement(qry);
            pstmt.setInt(1, custID);
            ResultSet rs = pstmt.executeQuery();

            String name = rs.getString("name");
            String address = rs.getString("address");
            String email = rs.getString("email");

            rs.close();

            Customer cust = new Customer (this, custID, name, address, email);

            cache.put(custID, cust);
            return cust;
        } catch (SQLException e) {
            dbm.cleanup();
            throw new RuntimeException("error finding department", e);
        }
    }

    // Insert new CartItem & returns it if the key does not already exist.

    public Customer insert (int custID, String name, String address, String email) {
        try {
            // make sure that the deptid is currently unused
            if (find(custID) != null)
                return null;

            String cmd = "insert into CUSTOMER(custID, name, address, email) "
                       + "values(?, ?, ?, ?)";
            PreparedStatement pstmt = conn.prepareStatement(cmd);
            pstmt.setInt(1, custID);
            pstmt.setString(2, name);
            pstmt.setString(3, address);
            pstmt.setString(4, email);

            pstmt.executeUpdate();

            Customer cust = new Customer(this, custID, name, address, email);

            cache.put(custID, cust);

            return cust;
        }
        catch(SQLException e) {
            dbm.cleanup();
            throw new RuntimeException("error inserting new department", e);
        }
    }

Any ideas on what is causing the error?

EDIT: Here is my CustomerDAO.java class, which handles the creation of the table along with other SQL commands.

public class CustomerDAO {

    private Connection conn;
    private DatabaseManager dbm;
    private Map<Integer, Customer> cache;

    public CustomerDAO (Connection conn, DatabaseManager dbm) {
        this.conn = conn;
        this.dbm = dbm;
        this.cache = new HashMap<Integer, Customer>();
    }

    static void create(Connection conn) throws SQLException {
        Statement stmt = conn.createStatement();
        String s = "create table CUSTOMER("
                + "name string, "
                + "custID string, "
                + "address string, "
                + "email string " 
                + "primary key(custID))";
        stmt.executeUpdate(s);
    }

    // Modifies CartItem table and adds foreign key constraints (tables need to already be created)

    //static void addConstraints(Connection conn) throws SQLException {
        //Statement stmt = conn.createStatement();
        //String s = "alter table Customer "
        //      + "foreign key(shoppingCartID) references shoppingCart(shoppingCartID)";
        //stmt.executeUpdate(s);
    //}

    //Finds CartItem object by primary key.

    public Customer find(int custID) {
        if (cache.containsKey(custID)) return cache.get(custID);

        try {
            String qry = "select name from CUSTOMER where custID = ?";
            PreparedStatement pstmt = conn.prepareStatement(qry);
            pstmt.setInt(1, custID);
            ResultSet rs = pstmt.executeQuery();

            String name = rs.getString("name");
            String address = rs.getString("address");
            String email = rs.getString("email");

            rs.close();

            Customer cust = new Customer (this, custID, name, address, email);

            cache.put(custID, cust);
            return cust;
        } catch (SQLException e) {
            dbm.cleanup();
            throw new RuntimeException("error finding department", e);
        }
    }

    // Insert new CartItem & returns it if the key does not already exist.

    public Customer insert (int custID, String name, String address, String email) {
        try {
            // make sure that the deptid is currently unused
            if (find(custID) != null)
                return null;

            String cmd = "insert into CUSTOMER(custID, name, address, email) "
                       + "values(?, ?, ?, ?)";
            PreparedStatement pstmt = conn.prepareStatement(cmd);
            pstmt.setInt(1, custID);
            pstmt.setString(2, name);
            pstmt.setString(3, address);
            pstmt.setString(4, email);

            pstmt.executeUpdate();

            Customer cust = new Customer(this, custID, name, address, email);

            cache.put(custID, cust);

            return cust;
        }
        catch(SQLException e) {
            dbm.cleanup();
            throw new RuntimeException("error inserting new department", e);
        }
    }


    //Clears Data from CartItem Table

    void clear() throws SQLException {
        Statement stmt = conn.createStatement();
        String s = "delete from CUSTOMER";
        stmt.executeUpdate(s);
        cache.clear();
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:15:55+00:00Added an answer on June 2, 2026 at 4:15 am

    The key is Here

    Caused by: java.sql.SQLSyntaxErrorException: Table/View 'CUSTOMER' does not exist.
    

    the solution ways :

    first step, check the connection of create method and query method are same database or not.

    second step, debug your code. Set a breakpoint in the create method, when the method executed
    then check table ‘CUSTOMER’ is create or not .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to simply insert a new row into my SQLite3 database
I am trying to do bulk insert into a table: use SalesDWH go BULK
I am trying to insert a row into a MySQL table and get it's
'43.005895','-71.013202' Trying to use: INSERT INTO table(fanDetLocZip, fanDetLocCity, fanDetLocState, fanDetLocLat, fanDetLocLong, fanDetLocTZ, fanDetLocDST) VALUES(00210,
I'm trying to insert a new object into my database. I followed a step-by-step
I currently trying to find a solution, how to ensure that a test fails
I'm currently trying to create a Profile Manager using a TIniFile to store the
I'm currently trying to put 5 videos back to back using AVMutableComposition like so:
I'm trying to do a cascading save on a large object graph using JPA.
I'm trying to insert values in the table but when I click on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.