79 lines
3.8 KiB
HTML
79 lines
3.8 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>StockDB.java</title>
|
||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
body {color: #000000; background-color: #ffffff; font-family: monospace}
|
||
|
pre {color: #000000; background-color: #ffffff; font-family: monospace}
|
||
|
table {color: #404040; background-color: #e9e8e2; font-family: monospace}
|
||
|
.ST1 {color: #ce54b8; font-family: monospace; font-style: italic}
|
||
|
.comment {color: #969696}
|
||
|
.ST0 {font-family: monospace; font-weight: bold}
|
||
|
.literal {color: #336bdd}
|
||
|
.string {color: #1e9347}
|
||
|
-->
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<table width="100%"><tr><td align="center">/Users/asdv5/Desktop/slcc/S24/2800/MP1_Ajax/src/main/java/edu/slcc/ajax/bl/StockDB.java</td></tr></table>
|
||
|
<pre>
|
||
|
@Override
|
||
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST0">create</span>(Stock t)
|
||
|
<span class="literal">throws</span> Exception
|
||
|
{
|
||
|
<span class="literal">int</span> result = 0;
|
||
|
Connection con = <span class="literal">null</span>;
|
||
|
<span class="literal">try</span>
|
||
|
{
|
||
|
con = con = <span class="literal">new</span> UtilitiesDatabase().connection(
|
||
|
<span class="string">"</span><span class="string">nyse</span><span class="string">"</span>, <span class="string">"</span><span class="string">root</span><span class="string">"</span>, <span class="string">"</span><span class="string">root</span><span class="string">"</span>, <span class="string">"</span><span class="string">com.mysql.jdbc.Driver</span><span class="string">"</span>);
|
||
|
}
|
||
|
<span class="literal">catch</span> (Exception e)
|
||
|
{
|
||
|
System.<span class="ST1">err</span>.println(e);
|
||
|
<span class="literal">throw</span> e;
|
||
|
}
|
||
|
PreparedStatement updateStock = <span class="literal">null</span>;
|
||
|
<span class="literal">try</span>
|
||
|
{
|
||
|
updateStock = con.prepareStatement(
|
||
|
<span class="string">"</span><span class="string">INSERT INTO stock (stock_id, company_name, price_current, price_closing, number_of_shares_available, number_of_shares_sold ) </span><span class="string">"</span>
|
||
|
+ <span class="string">"</span><span class="string">VALUES ( ?, ?, ? , ? ,? , ?)</span><span class="string">"</span>);
|
||
|
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());
|
||
|
<span class="literal">int</span> updateCount = updateStock.executeUpdate();
|
||
|
result = updateCount;
|
||
|
}
|
||
|
<span class="literal">catch</span> (Exception ex)
|
||
|
{
|
||
|
System.<span class="ST1">err</span>.println(ex.toString());
|
||
|
<span class="literal">throw</span> ex;
|
||
|
}
|
||
|
<span class="literal">finally</span>
|
||
|
{
|
||
|
<span class="literal">try</span>
|
||
|
{
|
||
|
<span class="literal">new</span> UtilitiesDatabase().closeDatabaseConnection(con);
|
||
|
<span class="comment">// close the resources </span>
|
||
|
<span class="literal">if</span> (updateStock != <span class="literal">null</span>)
|
||
|
{
|
||
|
updateStock.close();
|
||
|
}
|
||
|
}
|
||
|
<span class="literal">catch</span> (SQLException e)
|
||
|
{
|
||
|
System.<span class="ST1">err</span>.println(e.toString());
|
||
|
<span class="literal">throw</span> e;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
</pre></body>
|
||
|
</html>
|