/Users/asdv5/Desktop/slcc/S24/2800/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/StockDB.java |
@Override
public void create(Stock t)
throws Exception
{
int result = 0;
Connection con = null;
try
{
con = con = new UtilitiesDatabase().connection(
"nyse", "root", "root", "com.mysql.jdbc.Driver");
}
catch (Exception e)
{
System.err.println(e);
throw e;
}
PreparedStatement updateStock = null;
try
{
updateStock = con.prepareStatement(
"INSERT INTO stock (stock_id, company_name, price_current, price_closing, number_of_shares_available, number_of_shares_sold ) "
+ "VALUES ( ?, ?, ? , ? ,? , ?)");
updateStock.setString(1, t.getStockId());
updateStock.setString(2, t.getCompanyName());
updateStock.setDouble(3, t.getPriceCurrent());
updateStock.setDouble(4, t.getPriceClosing());
updateStock.setLong(5, t.getNumberOfSharesAvailable());
updateStock.setLong(6, t.getNumberOfSharesSold());
int updateCount = updateStock.executeUpdate();
result = updateCount;
}
catch (Exception ex)
{
System.err.println(ex.toString());
throw ex;
}
finally
{
try
{
new UtilitiesDatabase().closeDatabaseConnection(con);
if (updateStock != null)
{
updateStock.close();
}
}
catch (SQLException e)
{
System.err.println(e.toString());
throw e;
}
}
}