我正在尝试更新以及使用我的GUI将数据保存到我的数据库.我的问题是,如果我没有输入任何数据到我的数据库允许null的某些文本框,我会收到这种错误:java.sql.SQLException:第1行的'MonthlyIncome'列截断数据
我想要获得我的系统的运行平衡.为此,我从列AMOUNT获取jtable中所有数字的总和,并将总和减去txtLoanAmount中的值.这是我的代码片段:
String LoanAmount = txtLoanAmount.getText();
float f = Float.valueOf(LoanAmount.trim()).floatValue();
float balance = 0;
float sum = 0;
for(int i=0;i<=tableLedger.getRowCount()-1;i++) {
sum = sum + Float.parseFloat(tableLedger.getModel().getValueAt(i, 2).toString());
}
balance = f - sum;
System.out.println(balance);
Run Code Online (Sandbox Code Playgroud)
现在我收到错误消息:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "20,475.00"
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?任何帮助将不胜感激.谢谢
我有一个jtable.(tablesummary).其中一个专栏是EXPIRY.我想突出显示当前日期已过期的客户的行.
我已经得到了逻辑,但我不能让行变红或任何其他颜色.这是我的代码:
int count = (tableSummary.getRowCount());
NumberFormat formatter = new DecimalFormat("###,###");
String no = formatter.format(count);
txtNo.setText(no);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
String expDateString = sdf.format(cal.getTime()).toString();
for(int i=0; i<=tableSummary.getRowCount()-1; i++){
String nnn= tableSummary.getModel().getValueAt(i, 6).toString();
System.out.println(nnn);
int res = nnn.compareTo(expDateString);
if(res>=0){
System.out.println("if ni " + (res>=0));
}
else{
System.out.println("else ni" + (res>=0));
rowrenderer.setBackground(Color.RED);
}
}
Run Code Online (Sandbox Code Playgroud)
谁能帮我这个?因为它是我界面的主要亮点之一.提前致谢 !!:)
美好的一天 .我只是想问一下在给定日期添加天数.我有一个jtexfield(txtStart)和另一个jtexfield(txtExpiry).我需要在txtExpiry中显示自txtStart日期起102天后的日期.我正在使用KEYRELEASED事件.在输入txtStart之后,额外102天的日期将出现在txtExpiry中.
这是我的代码,但它仍然是错误的.
private void txtStartKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
// set calendar to 1 Jan 2007
int a = Integer.parseInt(txtStart.getText());
Calendar calendar = new GregorianCalendar(a,a,a);
calendar.add(Calendar.DAY_OF_MONTH,102);
PrintCalendar(calendar);
}
private void PrintCalendar(Calendar calendar){
// define output format and print
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
String date = sdf.format(calendar.getTime());
long add = Date.parse(date);
txtExpiry.setText(add); -----> this part here also has an error.
}
Run Code Online (Sandbox Code Playgroud)
我的代码仍然不会在txtExpiry中生成日期.提前致谢
收到帮助后,这是正确的代码:
private void txtStartKeyReleased(java.awt.event.KeyEvent evt) {
try {
Date date1;
date1 = …Run Code Online (Sandbox Code Playgroud)