Following is the code of my page.....
the problem is that the value of variable ip becomes "zero" every time...i want to stop it from being "zero"
the value of i should be equal to the value of production.....
Code:
package org.dst.db;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import org.dst.db.conn.pool.DBConnection;
import org.dst.db.conn.pool.Pool;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LOG implements DBEntity {
private static Logger logger = LoggerFactory.getLogger(LOG.class);
private String shift;
private int machine_id;
private double production;
private int warpBreak;
private int weftBreak;
private int pickMissing;
private int weftBar;
private int floating;
private int other;
private int pickPerInches;
private double ip=0;
private double pro1 =0;
protected LOG(String shift, int machine_id, double production, int warpBreak,
int weftBreak, int picMissing, int weftBar, int floating, int other,
int picksPerInches) {
this.shift = shift;
this.machine_id = machine_id;
this.production = production;
this.warpBreak = warpBreak;
this.weftBreak = weftBreak;
this.pickMissing = picMissing;
this.weftBar = weftBar;
this.floating = floating;
this.other = other;
this.pickPerInches = picksPerInches;
}
@Override
public boolean save() {
DBConnection dbCon = Pool.getInstance().getDBConnection();
Connection conn = dbCon.getConnection();
long oneDayInMillies = 86400000;
DateTime dateTime = new
DateTime().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
logger.info("Today's Time with 0.0.0 am is: " + dateTime);
Timestamp todaysTimestamp = new Timestamp(dateTime.getMillis());
try {
Statement st = conn.createStatement();
String query = "SELECT production,id FROM LOG"
+ " where shift='" + shift + "' and machine_id=" + machine_id
+ " and LOG_TIMESTAMP > '" + todaysTimestamp + "'"
+ " and LOG_TIMESTAMP < '" + new Timestamp(System.currentTimeMillis() + oneDayInMillies) + "'";
ResultSet rs = st.executeQuery(query);
if (rs.next()) {
{
logger.info("production is " + production);
logger.info("before ip is " + ip);
Double match = rs.getDouble(1);
logger.info(""+ match);
pro1=production+match-ip;
logger.info(" pro1 is " + pro1);
query = "UPDATE LOG SET "
+ "SHIFT = '" + shift + "', "
+ "LOG_TIMESTAMP = '" + new Timestamp(System.currentTimeMillis()) + "', "
+ "MACHINE_ID = " + machine_id + ","
+ "PRODUCTION = " + pro1+ ", "
+ "WARP_BREAK = " + warpBreak + ", "
+ "WEFT_BREAK = " + weftBreak + ", "
+ "MISSING_PICK = " + pickMissing + ", "
+ "FLOATING = " + floating + ", "
+ "OTHERS = " + other + ", "
+ "WEFT_BAR = " + weftBar + ", "
+ "PICKS_PER_INCHES = " + pickPerInches
+ " WHERE ID = " + rs.getInt("id");
logger.info("Going to Execute Query: " + query);
st.execute(query);
ip=production;
logger.info(" now i is " + i);
Pool.releaseConnection(dbCon);
return true;
}
}
query = "INSERT INTO LOG (SHIFT, LOG_TIMESTAMP, MACHINE_ID, PRODUCTION, WARP_BREAK, WEFT_BREAK, MISSING_PICK, FLOATING, OTHERS, WEFT_BAR, PICKS_PER_INCHES) "
+ "VALUES ('"
+ shift + "','"
+ new Timestamp(System.currentTimeMillis()) + "',"
+ machine_id + ","
+ production + ","
+ warpBreak + ","
+ weftBreak + ","
+ pickMissing + ","
+ floating + ","
+ other + ","
+ weftBar + ","
+ pickPerInches + ")";
logger.info("Going to Execute Query: " + query);
st.execute(query);
Pool.releaseConnection(dbCon);
} catch (SQLException ex) {
logger.error("SQLException in the DBStore: " + ex);
ex.printStackTrace();
return false;
}
return true;
}
}