Question: JAVA / MySQL I need help figureing out what is wrong my my method below. When i call the method, the Inserting into the Product

JAVA / MySQL

I need help figureing out what is wrong my my method below. When i call the method, the Inserting into the Product table works fine but it does not add to SeasonPass Table. I included an image of part of my EER Diagram.

The error message I get is:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL, 316, 'b21e', 'KarinaSeason', '2018-01-01', '2018-02-02')' at line 1.

This is how i called my method: addSeasonPass("b21e", "KarinaSeason", "2018-01-01", "2018-02-02", 100);

JAVA / MySQL I need help figureing out what is wrong my

_________________________________

public static void addSeasonPass(String productCode, String name, String seasonStartDate, String seasonEndDate, double cost) {

//1. Insert into Product table

//2. Write a query to get Product_ID

//3. Insert into SeasonPass

try {

String query = "INSERT INTO Product VALUES (NULL, 'S', '"+productCode+"', '"+cost+"')"; //making of product

//Connection

Connection conn = DatabaseInfo.getConnection();

Statement stmt = conn.createStatement();

stmt.executeUpdate(query);

//Query execution to get product ID

Statement stmt2 = conn.createStatement();

int productID = 0; //variable to store the productID

query = "SELECT Product_ID FROM Product WHERE Pr_Code = '"+productCode+"'"; //Query to retrieve productID

ResultSet rs = stmt2.executeQuery(query);

while(rs.next()) {

productID = rs.getInt("Product_ID");

}

query = "INSERT INTO SeasonPass (NULL, "+productID+", '"+productCode+"', '"+name+"', '"+seasonStartDate+"', '"+seasonEndDate+"')";

stmt.executeUpdate(query);

//Closing resources

stmt.close();

stmt2.close();

rs.close();

conn.close();

} catch (Exception e) {

e.printStackTrace();

return;

}

}

SeasonPass SeasonPass_ID INT (11) Product-ID INT(11) SeasonPass-Code VARCHAR(255) L- SP_Name VARCHAR(255) SP-SD VARCHAR(255) SPED VARCHAR(255) Indexes Product Product_ID INT (11) Product-Type VARCHAR(255) Pr-Code VARCHAR(255) Cost FLOAT(50) I+H Indexes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!