我已检索从数据库logTime Description该条的值和计算出的一小时前的时间从所检索的logtime.the代码用于检索logTime Description该条数据库查询的Java中的参数是如何从一个方法传递的变量值到另一个作为
public String database_Time() {
try {
con = getConnection();
String sql = "select max(logtime) from vacuum_analog_1mins";
clstmt = con.prepareCall(sql);
clstmt.execute();
rs = clstmt.getResultSet();
while (rs.next()) {
timestr = rs.getString(1);
}
} catch (Exception e) {
System.out.println("\nException in Bean in getDbTable(String code):" + e);
} finally {
closeConnection();
}
return timestr;
}
代码来计算一小时前时间:
public Date previostime() throws ParseException
{
database_Time();
String format = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
Date date = simpleDateFormat.parse(timestr);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int hours = calendar.get(Calendar.HOUR_OF_DAY);
hours--;
calendar.set(Calendar.HOUR_OF_DAY, hours);
Date fixedDate = calendar.getTime();
System.out.println("previous date is" + (fixedDate));
System.out.println("current date is" + timestr);
return fixedDate;
}
现在我想用这两个变量fixedDate和TIMESTR在我的另一种方法,其中这些变量将被用作sqlquery的参数为:
List <String> timeStr = new ArrayList <String>();
database_Time();
String atime[] = null;
database_Time();
previostime();
getConnection();
try {
con = getConnection();
String sql = "exec vcs_gauge @gauge_name=?,@first_rec_time=?,@last_rec_time=?";
clstmt = con.prepareCall(sql);
clstmt.setString(1, "vs1_bag");
clstmt.setString(2, "fixedDate");
clstmt.setString(3, "timestr");
clstmt.execute();
rs = clstmt.getResultSet();
while (rs.next()) {
// Just get the value of the column, and add it to the list
timeStr.add(rs.getString(1).substring(11, 16));
}
但没有结果请帮助我在哪里出错。我已将这些变量声明为全球。
fixedDate和TIMESTR被设置为变量的类? – Mailkov 2014-11-24 12:14:56
@Mailkov它们被声明为变量public Date fixedDate; \t public String timestr; – 2014-11-24 12:16:58
因为我看到你在你的方法中声明了fixedDate previoustime() – Mailkov 2014-11-24 12:18:28