无法从我的java中的MySql数据库中获取价值

时间:2014-08-21 12:10:37

标签: java mysql

我真的试图找出为什么我没有从表中获取值,即使我已经检查了我的数据。它没有显示错误但它只显示小字符串但不显示长字符串。

 private void booksTable(){
        String sql,bt,sql2,fsql="select * from Books order by title";
        int qty,loans;
        try{
            pst=conn.prepareStatement(fsql);
            rs=pst.executeQuery();

            if(rs.next()){
                booksTable.setModel(DbUtils.resultSetToTableModel(rs));
            }

            for(int row=0;row < booksTable.getRowCount();row++){
               bt=booksTable.getModel().getValueAt(row,0).toString();

               sql="select quantity from books where title = '"+bt+"'";
               pst=conn.prepareStatement(sql);
               rs=pst.executeQuery();
               qty=Integer.parseInt(rs.getString("quantity"));
               System.out.print(row+" "+qty+"\t");
               sql2="select * from loans where BookTitle = ?";
               pst2=conn.prepareStatement(sql2);
               pst2.setString(1,bt);
               rs=pst2.executeQuery();
               if(rs.next()){
               loanTable.setModel(DbUtils.resultSetToTableModel(rs));
               loans=loanTable.getRowCount();
               }else
                   loans=0;

               System.out.println(loans);

               if((qty - loans)==0 ){
                   pst3=conn.prepareStatement("update Books set status = 'Not Available' where title = '"+bt+"'");
                   pst3.execute();

               }else{
                   pst3=conn.prepareStatement("update Books set status = 'Available' where title = '"+bt+"'");
                   pst3.execute();
               }   

            }

0 个答案:

没有答案