1 32 33 34 44 package stockonline.ejb.sql; 45 46 import java.sql.*; 47 import javax.sql.DataSource ; 48 49 public class StockTx 50 { 51 53 final static boolean verbose = false; 54 private java.text.SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat ("dd/MM/yy"); 55 56 public StockTx() {} 57 58 61 public int create ( Connection conn, 62 String txType, 63 int accountID, 64 int stockID, 65 int amount, 66 float price) 67 throws Exception 68 { 69 if(verbose) 70 { 71 System.out.println("Transaction.create(Connection conn) called"); 72 System.out.println("txType = " + txType); 73 System.out.println("accountID = " + accountID); 74 System.out.println("stockID = " + stockID); 75 System.out.println("amount = " + amount); 76 System.out.println("price = " + price); 77 } 78 79 int txID = SeqGenerator.getNextTxID(conn); 80 if(verbose) System.out.println("generated txID = " + txID); 81 82 create_Imp(conn, txID, txType, accountID, stockID, amount, price); 83 84 return txID; 85 } 86 87 private void create_Imp ( Connection conn, 90 int trans_id, 91 String trans_type, 92 int sub_accno, 93 int stock_id, 94 int amount, 95 float price) 96 throws Exception 97 { 98 PreparedStatement pstmt = null; 99 100 try 101 { 102 String sql = "INSERT INTO StockTransaction VALUES (?, ?, ?, ?, ?, ?, ?)"; 103 if(verbose) System.out.println(sql); 104 105 String currentDate = dateFormatter.format( new java.util.Date () ); 106 if(verbose) System.out.println(currentDate); 107 108 pstmt = conn.prepareStatement(sql); 109 pstmt.setInt(1, trans_id); 110 pstmt.setString(2,trans_type); 111 pstmt.setInt(3, sub_accno); 112 pstmt.setInt(4, stock_id); 113 pstmt.setInt(5, amount); 114 pstmt.setFloat(6, price); 115 pstmt.setString(7,currentDate); 116 117 pstmt.executeUpdate(); 118 } 119 catch(SQLException ex) 120 { 121 System.err.println("Exception in StockTransaction.create_Imp(): " + ex.getMessage()); 122 throw new Exception (ex.toString()); 123 } 124 finally 125 { 126 if(pstmt!=null) pstmt.close(); 127 } 128 } 129 } | Popular Tags |