Hi

Descriptive:
My program runs every six hours.
Two independent tables are setup - each with 4,100 records
On the first run a trade is opened and table 1 has a new record added and
the oldest one is deleted - all OK
On the second run, I am expecting the TRADES table to have a new record
added.
The subroutine to add a new record is triggered by the boolean variable
'trade' which is true
The program prints out the correct trade number as 4,101

The code:

// Adding a new record (if required) to the Derby database TRADES table
// [b] add a new record to the table TRADES  
if (trade) {
// parameter 1 is Trade_No (int), 
// parameter 2 is Class1_predicted (varchar), parameter 3 is
Class2_predicted (varchar)
// parameter 4 is Class3_predicted (varchar), parameter 5 is
Class4_predicted (varchar)
// parameter 6 is Class5_predicted (varchar), parameter 7 is
Class6_predicted (varchar)
// parameter 8 is Class7_predicted (varchar), parameter 9 is
Ensemble_predicted (varchar)
// parameter 10 is Profit/Loss (dec)

fw.writetoFile(("Adding a new trade record Number: " + trade_no),
FILE_NAME);
psInsert = conn.prepareStatement("INSERT INTO TRADES VALUES (?, ?, ?, ?, ?,
?, ?, ?, ?, ?)");
statements.add(psInsert);

psInsert.setInt(1, trade_no);
psInsert.setString(2, curr_class1_predicted);
psInsert.setString(3, curr_class2_predicted);
psInsert.setString(4, curr_class3_predicted);
psInsert.setString(5, curr_class4_predicted);
psInsert.setString(6, curr_class5_predicted);
psInsert.setString(7, curr_class6_predicted);
psInsert.setString(8, curr_class7_predicted);
psInsert.setString(9, curr_ensemble_predicted);
psInsert.setNull(10, java.sql.Types.DECIMAL);

psInsert.executeUpdate();

myConsole.getOut().println("Inserted newest record:- Trade Number: " +
trade_no);
fw.writetoFile(("Inserted newest record:- Trade Number: " + trade_no),
FILE_NAME);
trade = false;

// commit the above transactions
conn.commit();

// retrieve and output trade number of latest record from the table TRADES
rs = s.executeQuery("SELECT * FROM TRADES ORDER BY TRADE_NO DESC FETCH FIRST
ROW ONLY");
rs.next();
int trade_no_temp3 = rs.getInt("Trade_No");

fw.writetoFile(("Latest trade record:- Trade Number: " + trade_no_temp3),
FILE_NAME);

} // end of adding new trade record to database table TRADES

The error message(s):

mining routine finished
simulation routine commenced
simulation routine finished
final prediction routine commenced
Prediction_Trend: 0.0
Current Trade Direction: 
debug: we get to here(8)
final prediction routine finished
Weka non-initialization successful
Weka finished
No. 2 - Initialize: false
No. 2 - myCanTrade: false
No. 2 - do_not_trade: false
No. 2 - curr_trade_dir: 
No. 2 - prev_trade_dir: Down
Inserted newest record:- Trading_Date/Trading_Time: 2017-5-23, 12
Oldest record:- Trading_Date/Trading_Time: 2012-02-06, 6
Deleted oldest record
*Adding a new trade record Number: 4101
*
----- SQLException -----
 SQL State: 23505
 Error Code: 20000
 Message: The statement was aborted because it would have caused a duplicate
key value in a unique or primary key constraint or unique index identified
by 'SQL170412104646890' defined on 'TRADES'.

----- SQLException -----
 SQL State: 25001
 Error Code: 20000
 Message: Cannot close a connection while a transaction is still active.
Derby finished
Label: USDJPY_2352017_6
Currency Pair: USDJPY
Closed Trade: USDJPY_2352017_64101 | P/L: -15.5 pips
PL_updates = 1.0

Many thanks

Bob M
New Zealand



--
View this message in context: 
http://apache-database.10148.n7.nabble.com/Updating-2-derby-tables-tp147386p147428.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.

Reply via email to