0

这是我遇到问题的代码块,我相信问题出在创建表部分,因为在那之后它不会执行 printLn,使用 DOUBLE 会导致缺少关键字错误,使用 FLOAT 或 NUMBER 会导致缺少右括号

public void createCoffeeTable() {
    // Create a Table           
    try {
        String create = "CREATE TABLE Coffee "
                + "(coffeeId NUMBER PRIMARY KEY NOT NULL, cType VARCHAR(40),cSize VARCHAR(15),price DOUBLE(4,2)";
        pstmt = conn.prepareStatement(create);
        pstmt.executeUpdate();
        // Insert data into table
        String insertString1 = "INSERT INTO Coffee(coffeeId,cType,cSize,price) "
                + "values(CoffeeId_seq.nextVal,?,?,?)";
        pstmt = conn.prepareStatement(insertString1);

        pstmt.setString(1, "Espresso");
        pstmt.setString(2, "Solo");
        pstmt.setDouble(3, 2.00);
        pstmt.execute();

        pstmt.setString(1, "Espresso");
        pstmt.setString(2, "Doppio");
        pstmt.setDouble(3, 2.75);
        pstmt.execute();

        pstmt.setString(1, "Americano");
        pstmt.setString(2, "Medium");
        pstmt.setDouble(3, 2.50);
        pstmt.execute();

        pstmt.setString(1, "Americano");
        pstmt.setString(2, "Large");
        pstmt.setDouble(3, 3.00);
        pstmt.execute();

        pstmt.setString(1, "Cappuccino");
        pstmt.setString(2, "Medium");
        pstmt.setDouble(3, 3.00);
        pstmt.execute();

        pstmt.setString(1, "Cappuccino");
        pstmt.setString(2, "Large");
        pstmt.setDouble(3, 3.75);
        pstmt.execute();

        pstmt.setString(1, "Mocha");
        pstmt.setString(2, "Medium");
        pstmt.setDouble(3, 3.00);
        pstmt.execute();

        pstmt.setString(1, "Mocha");
        pstmt.setString(2, "Large");
        pstmt.setDouble(3, 3.75);
        pstmt.execute();

        pstmt.setString(1, "Flat White");
        pstmt.setString(2, "Medium");
        pstmt.setDouble(3, 2.50);
        pstmt.execute();

        pstmt.setString(1, "Flat White");
        pstmt.setString(2, "Large");
        pstmt.setDouble(3, 3.00);
        pstmt.execute();

        System.out.println("Coffee table created");
    } catch (SQLException ex) {
        System.out.println("SQL Exception creating and inserting values into Coffee" + ex.getMessage());
    }
}


public void createBillTable() {
    // Create a Table           
    try {
        String create = "CREATE TABLE Bill "
                + "(transId NUMBER PRIMARY KEY NOT NULL,Bill DOUBLE(10,2),name VARCHAR(40)"
                + "FOREIGN KEY (name) REFERENCES Cashier (Name) ON DELETE CASCADE";
        pstmt = conn.prepareStatement(create);
        pstmt.executeUpdate();

        // Insert data into table
        String insertString1 = "INSERT INTO Bill(transId,Bill,name) "
                + "values(?,?,?)";
        pstmt = conn.prepareStatement(insertString1);

        pstmt.setDouble(1, 10.20);
        pstmt.setString(2, "Peter Tosh");
        pstmt.execute();

        pstmt.setDouble(1, 21.00);            
        pstmt.setString(2, "Donna Summers");
        pstmt.execute();

        pstmt.setDouble(1, 2.50);
        pstmt.setString(2, "James Maynard Keenan");
        pstmt.execute();

        System.out.println("Bill table created");
    } catch (SQLException ex) {
        System.out.println("SQL Exception creating and inserting values into Bill" + ex.getMessage());
        System.exit(1);
    }
}

任何帮助将非常感激

4

0 回答 0