gpt4 book ai didi

java - 程序卡住 Java MySQL

转载 作者:行者123 更新时间:2023-11-29 18:21:33 25 4
gpt4 key购买 nike

我想在我的java应用程序中获取MySQL数据库数据,所以我使用这段代码:

//  Data retriveing from database HB_Cash
try{
connectDB();
Statement st = con.createStatement();
rs = st.executeQuery("select * from tbl_day_sheet_status_reports");

while(rs.next()){
PB_cash.setText(rs.getString("Handing_Balance_(CASH)"));
String sv = rs.getString("Handing_Balance_(CASH)");
sv = PB_cash.getText();
int billNumber = Integer.valueOf(sv);
sv = Integer.toString(billNumber);
PB_cash.setText(sv);
}
con.close();

}catch(Exception ex){
JOptionPane.showMessageDialog(this, ex.getMessage());
}

当我调用这段代码时,它工作正常,但有时会卡住就像 2160.81 数据插入,如果之后有更多数据,每次都会用消息框显示此数据:

enter image description here

所以我使用这个 SQL 创建语句:

CREATE TABLE `tbl_day_sheet_status_reports` (
`DaySheet_no` int(11) NOT NULL,
`Date` varchar(45) DEFAULT NULL,
`Previous_Balance_(CASH)` double DEFAULT NULL,
`Previous_Balance_(CHQUE)` double DEFAULT NULL,
`Daily_Collection_(CASH)` double DEFAULT NULL,
`Daily_Collection_(CHQUE)` double DEFAULT NULL,
`Daily_Collection_(CHQUE_NUMBER)` varchar(45) DEFAULT NULL,
`Bank_Diposits_(CASH)` double DEFAULT NULL,
`Bank_Diposits_(CHQUE)` double DEFAULT NULL,
`Handing_Balance_(CASH)` double DEFAULT NULL,
`Handing_Balance_(CHQUE)` double DEFAULT NULL,
PRIMARY KEY (`DaySheet_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

请帮我解决这个问题。

最佳答案

   try{

connectDB();

Statement st = con.createStatement();

rs = st.executeQuery("select * from tbl_day_sheet_status_reports");

while(rs.next()){
// You Can get this value as a float of Double
//Due to Class Cast Exception your code is not working when value
//comes in float
PB_cash.setText(rs.getDouble("Handing_Balance_(CASH)")+"");
String sv = rs.getDouble("Handing_Balance_(CASH)")+"";
sv = PB_cash.getText();
double billNumber = Double.valueOf(sv);
sv = Integer.toString(billNumber);
PB_cash.setText(sv);
}
con.close();

}catch(Exception ex){
JOptionPane.showMessageDialog(this, ex.getMessage());
}

关于java - 程序卡住 Java MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46535886/

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