com.microsoft.sqlserver.jdbc.SQLServerException:将varchar值'014051452X'转换为数据类型int时转换失败

时间:2014-10-26 01:12:11

标签: java sql-server jdbc

public void book_copies_table_clicked(){
        try { 
            dtm1.setRowCount(0);
            int row = dc.book_search_table.getSelectedRow();
            Statement s2 = con.createStatement();
            ResultSet rs1 = s2.executeQuery("select branch_id, copies from book_copies where book_id="+dc.book_search_table.getValueAt(row, 0).toString());
            while(rs1.next()){
                int branchID = rs1.getInt(1);
                String branchID1 = Integer.toString(branchID);
                int copies = rs1.getInt(2);
                String copies1 = Integer.toString(copies);
                dtm1.addRow(new String[] {branchID1,copies1});
            }

        } catch (SQLException ex) {
            Logger.getLogger(implementation_class.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

这是我点击其他表格中的某一行时会触发的函数。它正在工作,但我继续得到例外:

Oct 25, 2014 8:03:31 PM library_management.implementation_class book_copies_table_clicked
SEVERE: null
com.microsoft.sqlserver.jdbc.SQLServerException: Conversion failed when converting the varchar value '014051452X' to data type int.

还有更多行。我没有将任何东西从字符串转换为int左右。但我最终还是得到了这些。

book_copies表有3列。 book_id:varchar; branch_id:smallint;副本:smallint

我尝试在函数的catch块中放置一条打印消息,并且打印出来意味着它正在捕获异常,但我不知道为什么。

0 个答案:

没有答案