无法从MYSQL数据库中检索值

时间:2013-07-18 17:14:13

标签: java mysql

public boolean getDateMatches(String date){
    try {
        query="select * from "+TABLE_NAME+" "
                + "where "+MATCH_DATE+"='"+date+"';";
        pst=con.prepareStatement(query);
        rs=pst.executeQuery();
        while(rs.next()){
            matchNos.add(rs.getInt(MATCH_NO));//array list of Integers
            homeTeams.add(rs.getString(HOME_TEAM));
            awayteams.add(rs.getString(AWAY_TEAM));
            matchTimes.add(rs.getString(MATCH_TIME));
            matchDates.add(rs.getString(MATCH_DATE));
        }
        flag=true;
    } catch (SQLException ex) {
        flag=false;
    }
    finally{
        return flag;
    }
}

//Function to get date after given number of days
public static String getDate(int days){
    SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy");
    Date date=new Date();
    Calendar c=Calendar.getInstance();
    c.setTime(date);
    c.add(Calendar.DATE, days);
    return sdf.format(c.getTime()).toString(); 
  }

第一个是我用来从数据库中检索值的函数,当我以字符串格式传递日期时它工作正常但是当我使用getDate()从系统中检索日期并将日期传递给第一个函数时没有值是存储在matchNos,homeTeams,awayTeams,matchTimes和matchDates

注意:第二个函数返回正确的值

请提出解决方案 提前致谢

0 个答案:

没有答案