Is this class acceptable to use and would it be easy enough to call methods from a web service client?
(I will be using the Eclipse IDE, Apache Axis 2 framework, Apache Tomcat server and a mySQL database -- if any of that information is relevant.)
public class Stock
{
/**
* Adds a new product to the database
*
* @param name -- name of the game product (e.g - call of duty, grand theft auto)
* @param genre -- genre of the game product (e.g - action, adventure)
* @param platform -- platform of the game product (e.g - playstation 4, xbox one)
* @param developer -- developer of the game product (e.g - sledgehammer games, rockstar north)
* @param publisher -- publisher of the game product (e.g - activision, rockstar games)
* @param ageRating -- age rating of the game product (based on the PEGI rating system)
* @param price -- price of the game product in pounds (£)
* @param quantity -- quantity of the game products
* @param description -- brief description of the game product
*/
public void addProduct(String name, String genre, String platform, String developer, String publisher,
int ageRating, double price, int quantity, String description)
{
try
{
// 1. Connects to the database
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/Products", "root", "root");
// 2. Executes SQL query
String SqlString = "INSERT INTO Games(Game_Name, Genre, Platform, Developer, Publisher, Age_Rating, Price, Quantity, Description) VALUES(?,?,?,?,?,?,?,?,?)";
PreparedStatement prepStatement = connection.prepareStatement(SqlString);
prepStatement.setString(1, name);
prepStatement.setString(2, genre);
prepStatement.setString(3, platform);
prepStatement.setString(4, developer);
prepStatement.setString(5, publisher);
prepStatement.setInt(6, ageRating);
prepStatement.setDouble(7, price);
prepStatement.setInt(8, quantity);
prepStatement.setString(9, description);
// 3. Updates the database using the SQL query
prepStatement.executeUpdate();
// 4. Closes database connection
connection.close();
}
catch(Exception e)
{
System.out.println("Problems were encountered when trying to insert new records to the database. (Ref. to SQL statements)");
}
}
}