问题:ACCESS里是股票的价格,每一列中是一只股票的每天的价格;我想要判断股票是否有某日没有交易(已赋值为-1),如果有的话,用前一天的价格来填补.现在发现我用来表示今天价格()和昨天价格()的变量里的数据一起动了,请教哪里出了问题,该如何处理?多谢 !!
代码:
import java.sql.*;public class PriceLateday {
public static void main(String[] args) { String dbDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=./price1.mdb";
String user="";
          String password="";
Connection connection=null;
Statement selectStatement=null;
Statement selectTradedate=null;
Statement updateStatement=null;
ResultSet  results=null;
ResultSet tradeTime=null;
/*股票比较多,分多个表,每个表200列*/
String[] finaldata=new String[]{"priceASH1","priceASH2","priceASH3","priceASH4","priceASH5"};

//数据库驱动
try{
Class.forName(dbDriver).newInstance();
}
catch(Exception e){
System.out.println(e);
}

        //数据库更新,按前一日价格更新缺失的价格
try{
connection=DriverManager.getConnection(url,user,password);
selectStatement=connection.createStatement();
selectTradedate=connection.createStatement();
updateStatement=connection.createStatement();

for(int i=0;i<=finaldata.length;i++){
int volumeOfTable=200;
String tableName=finaldata[i]; for(int j=1;j<=volumeOfTable;j++){

    double todayPrice=-5;/*表示当天的价格,随便给个负数*/
    double latePrice=-4;/*表示前一天的价格,随便给个负数*/                         results=selectStatement.executeQuery("select * from "+tableName+"");
    
     ResultSetMetaData rsdm=results.getMetaData();
     String columnname=rsdm.getColumnName(j+1);/*取得每列股票的代码,就是列的名字,第一列是日期*/
    
while(results.next){  
     todayPrice=results.getDouble(j+1); tradeTime=selectTradedate.executeQuery("select TradeDate from "+tableName);      while(tradeTime.next()){
         
                                 Date today=tradeTime.getDate(1);                      
                                 if(todayPrice==-1){
                         System.out.println(today);
                         String str="update "+tableName+" set "+columnname+"="+latePrice+
                         " where TradeDate=#"+today+"#";
                         System.out.println(str);/*谨慎起见,先不更新,只是输出*/
                         //updateStatement.executeUpdate(str);
                         }
                         else{
                         ;
                         }
                         latePrice=todayPrice;/*每一次循环到末,就把今天的价格赋予昨天*/                        
       }
     tradeTime.close();
    }
    results.close();
    }
}
}
catch(Exception ex){
System.out.println(ex.getMessage());
System.out.println("数据库写入失败");

}

try{
selectStatement.close();
updateStatement.close();
selectTradedate.close();
connection.close();
}
catch(Exception ex){
System.out.println("数据库关闭失败");
}

}}