gpt4 book ai didi

java - 代号一 SQLite 数据问题

转载 作者:行者123 更新时间:2023-12-02 13:29:10 26 4
gpt4 key购买 nike

我正在开发 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com