db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bob M <rgmatth...@orcon.net.nz>
Subject Commiting several operations
Date Sun, 01 Dec 2013 23:44:40 GMT
Hi there

I am wishing to commit several add, delete, update operations, after the
following code:-

I added a single line with commit; but got an error message - and so I
clearly don't understand 'commit'

******************************************************************************
// retrieve the last record from the table
rs = s.executeQuery("SELECT * FROM USD_JPY ORDER BY Date DESC, Time DESC
FETCH FIRST ROW ONLY");
rs.next();
String Date1 = rs.getString("Date");
String Time1 = rs.getString("Time");

myConsole.getOut().println("Date/Time: " + Date1 + ", " + Time1);

// Update this record by adding predicted return and predicted class
psUpdate = conn.prepareStatement("UPDATE USD_JPY SET
Return_predicted=?,Class_predicted=?");
statements.add(psUpdate);

psUpdate.setDouble(1, return_current);
psUpdate.setString(2, class_current);

myConsole.getOut().println("Updated latest record with predicted return: " +
return_current + ", predicted class: " + class_current);

// add a new current record to the table

// add the new current record to the dbase
// parameter 1 is Date (varchar), parameter 2 is Time (int)
// parameter 3 is DOW_num (int), parameter 4 is DOW_nom (varchar)
// parameter 5 is Hour_num (int), parameter 6 is Hour_nom (varchar)
// parameter 7 is return (dec), parameter 8 is MA2 (dec)
// parameter 9 is MA6 (dec), parameter 10 is MA10 (dec)
// parameter 11 is class (varchar)

// parameter 12 is Return_predicted (dec)
// parameter 13 is Class_predicted (varchar)

psInsert = conn.prepareStatement("INSERT INTO USD_JPY VALUES (?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?, ?, ?)");
statements.add(psInsert);

psInsert.setString(1, date_current);
psInsert.setInt(2, time_current);
psInsert.setInt(3, DOW_numeric);
psInsert.setString(4, DOW_nominal);
psInsert.setInt(5, Hour_numeric);
psInsert.setString(6, Hour_nominal);
psInsert.setDouble(7, return_current);
psInsert.setDouble(8, MA2);
psInsert.setDouble(9, MA6);
psInsert.setDouble(10, MA10);
psInsert.setString(11, class_current);
psInsert.setDouble(12, return_predicted);
psInsert.setString(13, class_predicted);

myConsole.getOut().println("Inserted new record");

// retrieve and output date and time of oldest record from the table
rs = s.executeQuery("SELECT * FROM USD_JPY ORDER BY Date ASC, Time ASC FETCH
FIRST ROW ONLY");
rs.next();
String Date2 = rs.getString("Date");
int Time2 = rs.getInt("Time");

myConsole.getOut().println("Date/Time: " + Date2 + ", " + Time2);

// and now delete this record.............

s.setCursorName("MYCURSOR");
rs = s.executeQuery("SELECT * from USD_JPY WHERE Date = '" + Date2 + "' AND
Time = " + Time2 
+ " FOR UPDATE");
rs.next();
conn.prepareStatement("DELETE FROM USD_JPY WHERE CURRENT OF
MYCURSOR").executeUpdate();

myConsole.getOut().println("Deleted oldest record");
***********************************************************

Bob M




--
View this message in context: http://apache-database.10148.n7.nabble.com/Commiting-several-operations-tp135841.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.

Mime
View raw message