More code ................................ psInsert = conn.prepareStatement("INSERT INTO TABLE1 VALUES (?, ?, ?)"); statements.add(psInsert);
psInsert.setString(1, aaaa); psInsert.setInt(2, bbbbb); psInsert.setDouble(3, ccccc); psInsert.executeUpdate(); fw.writetoFile(("Inserted newest record:- Trading_Date/Trading_Time: " + date_current + ", " + time_current), FILE_NAME); // retrieve and output date and time of oldest record from the table TABLE1 rs = s.executeQuery("SELECT * FROM TABLE1 ORDER BY Trading_Date ASC," + " Trading_Time ASC FETCH FIRST ROW ONLY"); rs.next(); String Date_temp = rs.getString("Trading_Date"); int Time_temp = rs.getInt("Trading_Time"); fw.writetoFile(("Oldest record:- Trading_Date/Trading_Time: " + Date_temp + ", " + Time_temp), FILE_NAME); // and now delete this record............. s.setCursorName("MYCURSOR"); rs = s.executeQuery("SELECT * from TABLE1 WHERE Trading_Date = '" + Date_temp + "' AND Trading_Time = " + Time_temp + " FOR UPDATE"); rs.next(); conn.prepareStatement("DELETE FROM TABLE1 WHERE CURRENT OF MYCURSOR").executeUpdate(); fw.writetoFile(("Deleted oldest record"), FILE_NAME); // commit the above transactions conn.commit(); // end of adding new record and deleting oldest record from database table TABLE1 // Adding a new record (if required) to the Derby database TABLE2 table // [b] add a new record to the table TABLE2 if (trade) { 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, ddddd); psInsert.setString(2, eeeee); psInsert.setString(3, fffffff); psInsert.setString(4, ggggg); psInsert.executeUpdate(); 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 TABLE2 rs = s.executeQuery("SELECT * FROM TABLE2 ORDER BY Trading_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); Bob M -- View this message in context: http://apache-database.10148.n7.nabble.com/Updating-2-derby-tables-tp147386p147389.html Sent from the Apache Derby Users mailing list archive at Nabble.com.