Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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);

image text in transcribed

_________________________________

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

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

Recommended Textbook for

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions