简体   繁体   English

程序卡死了Java MySQL

[英]Program stuck Java MySQL

I want to get MySQL database data in my java application, So I use this code for that: 我想在我的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());
    }

When I called this code, it works fine, but sometimes it's stuck like the 2160.81 data is inserted if it has more data after that, every time it shows this data with message box: 当我调用此代码时,它可以正常工作,但有时会卡住,就像2160.81数据插入一样,如果之后它有更多数据,则每次在消息框中显示此数据时:

在此处输入图片说明

So I use this SQL create statement: 因此,我使用以下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;

Please help me to fix this issue. 请帮助我解决此问题。

   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());
}

I change the (Er Kapil Mehta) code like this and its works perfect Thanks for your help 我像这样更改(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());
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM