Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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)");
}
}
}
Posted
Comments
Sergey Alexandrovich Kryukov 19-Nov-14 12:52pm    
Just a note: a whole approach is wrong. If you have poor understanding of how a service will be used, don't develop it in detail. Start with modeling the whole thing; develop service part with the sample of the client, all together.
—SA
Member 10664689 19-Nov-14 13:54pm    
Thank you for your input. The web service is part of a group project for university, where one of us develops the client and the other the service. However, my partner has proven to be unreliable, so I have taken it upon myself to create the client.

Would you recommend that I create a fresh project and develop the client and service side-by-side?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900