我想在我的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数据一样,如果之后有更多的数据,每次用消息框显示这个数据时都会插入:
所以我使用这个SQL create语句:
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;
请帮我解决这个问题。
答案 0 :(得分:0)
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());
}
答案 1 :(得分:0)
我改变了(Er Kapil Mehta)这样的代码,它的作品非常完美 谢谢你的帮助
try{
connectDB();
Statement st = con.createStatement();
rs = st.executeQuery("select * from tbl_day_sheet_status_reports");
while(rs.next()){
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 = Double.toString((Double) billNumber);
PB_cash.setText(sv);
}
con.close();
}catch(Exception ex){
JOptionPane.showMessageDialog(this, ex.getMessage());
}