java - 代号一 SQLite 数据问题

标签 java android sqlite oop codenameone

我正在开发 Codename one SQLite 项目,虽然我遇到了一些问题,但我正在尝试当我单击日历上的某个特定日期时,它会检查该日期是否存在于数据库中,但是当我单击日历上的某个特定日期时,它会检查该日期是否存在于数据库中,但是当我首先在应用程序启动后单击特定日期,它给出了该日期的准确出现,但第二次它将以前的日期出现添加到当前日期出现并显示其总和。那么如何解决呢?

下面是我的代码:-

public class Customised extends Calendar{
         ArrayList<String[]> data = new ArrayList<>();



         public Customised(){

    }

    @Override
    protected void updateButtonDayDate(Button dayButton, int currentMonth, int day) {
             dayButton.setText(""+day);
       dayButton.addActionListener(new ActionListener() {
           @Override
           public void actionPerformed(ActionEvent evt) {

               try{
        cur =  db.executeQuery("SELECT Date from CalendarData WHERE Date = ? ", dateLabel.getText());
         int columns = cur.getColumnCount();
                      if(columns > 0) {
                    boolean next = cur.next();
                    if(next) {

                        String[] columnNames = new String[columns];
                        for(int iter = 0 ; iter < columns ; iter++) {
                            columnNames[iter] = cur.getColumnName(iter);
                        }
                        while(next) {
                            Row currentRow = cur.getRow();
                            String[] currentRowArray = new String[columns];
                            for(int iter = 0 ; iter < columns ; iter++) {
                                currentRowArray[iter] = currentRow.getString(iter);
                            }
                            data.add(currentRowArray);
                            next = cur.next();
                        }
                        Object[][] arr = new Object[data.size()][];
                        data.toArray(arr);
                    }
                      }
             }catch(IOException e){
                 e.printStackTrace();
             }
               int i;
               for( i = 0 ; i< data.size(); i++){
                   Log.p(data.get(i)[0]);
               }
               Label a = new Label(dateLabel.getText());
               Label b = new Label(""+i);
               Container container1 = TableLayout.encloseIn(2, a,b);
               calendar.add(container1);
              Util.cleanup(data);

              // dayButton.getAllStyles().setBgColor(0xef5555);
     //  dayButton.setText("* "+day);

           }      
       });
    }

    @Override
    protected Button createDay() {
       Button day = new Button();
        day.setAlignment(CENTER);
        day.setUIID("CalendarDay");
        day.setEndsWith3Points(false);
        day.setTickerEnabled(false);
        return day;
    }
    }

}

最佳答案

我得到了这个问题的答案:-

@Override
protected void updateButtonDayDate(Button dayButton, int currentMonth, int day) {

         dayButton.setText(""+day);
   dayButton.addActionListener(new ActionListener() {
       @Override
       public void actionPerformed(ActionEvent evt) {

           try{
    cur =  db.executeQuery("SELECT Date from CalendarData WHERE Date = ? ", dateLabel.getText());
     int columns = cur.getColumnCount();
                  if(columns > 0) {
                boolean next = cur.next();
                if(next) {

                    String[] columnNames = new String[columns];
                    for(int iter = 0 ; iter < columns ; iter++) {
                        columnNames[iter] = cur.getColumnName(iter);
                    }
                    while(next) {
                        Row currentRow = cur.getRow();
                        String[] currentRowArray = new String[columns];
                        for(int iter = 0 ; iter < columns ; iter++) {
                            currentRowArray[iter] = currentRow.getString(iter);
                        }
                        data.add(currentRowArray);
                        next = cur.next();
                    }
                    Object[][] arr = new Object[data.size()][];
                    data.toArray(arr);
                }
                  }
         }catch(IOException e){
             e.printStackTrace();
         }

           for( i = 0 ; i< data.size(); i++){
               Log.p(data.get(i)[0]);
           }
           Label a = new Label(dateLabel.getText());
           Label b = new Label(""+i);

           Container container1 = TableLayout.encloseIn(2, a,b);
           if(calendar.contains(container1)== true){
               calendar.removeComponent(container1);
           calendar.add(container1);
           }else{
               calendar.add(container1);
           }

          data.clear();

          // dayButton.getAllStyles().setBgColor(0xef5555);
 //  dayButton.setText("* "+day);

       }      
   });
}

感谢您的回复。

关于java - 代号一 SQLite 数据问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43256370/

相关文章:

java - 解析字符串输出到文件

c# - 使用 3 个文本框过滤数据库结果

java - 获取表示给定 float (以毫秒为单位)的时间的字符串的简单方法

java - 使用变量参数在没有 ArrayList 的情况下查找数字的乘积?

android - 在 android youtube 播放器中渲染和播放哪个文件

java - 在 Intent 中传递的同一个包上使用 putParcelableArrayList 和 putInt

mysql - 准备好的语句的内部结构是什么样的?

sqlite - Haskell 变量 "not in scope: type variable ' m'"

java - 为什么在Java中通过方法定义静态字段之前就可以访问它?

android - 使用持续执行的 TimerTask 优化服务运行