将对象输入对话框值传递并解析到数据库 table

passing and parsing object input dialog value to database table

I want to know how to get integer value from input dailog box

并在select语句中查询 看起来我的错误输入框类型根据我的下面是对象,我不知道如何将对象解析为整数以便被 select 语句接受 请告知如何处理对象类型以获取输入框变量并将其注入我的 select

private void InputVal(){

       // here is the input box to retrieve user entry
      Object journal_no = JOptionPane.showInputDialog(
              null,    "Please enter Journal No.?:\n",  "Search", JOptionPane.PLAIN_MESSAGE,
              null,null,"");
      if (journal_no.equals("")){
          JOptionPane.showMessageDialog(null, "Please enter correct No.");
          return;


      }
       // HERE I WILL CALL SQL STATEMENT TO LOAD Table rely on //inputbox 
      try {
  String host1=  "jdbc:derby://localhost:1527//accountsdb";
  String uName1="accounts";
  String uPass1="accounts";
   con1=DriverManager.getConnection(host1,uName1 ,uPass1);
    //String sql ="select * from log where password= jTuser.getText()  " ;

  String sql1="select * from JOUNRAL Where journal_no=" +   journal_no + "  ";
   stmt1=con1.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, 
   ResultSet.CONCUR_UPDATABLE);
       rs=stmt1.executeQuery(sql1);

            while (rs.next()){ 
                //Load values into
             Date Jdate  =rs.getDate("journal_date"); 
            txt_date.setDate(Jdate);
            int JNo;
      JNo = rs.getInt("journal_no");
            jLjournal_no.setText(Integer.toString(JNo));
            }
        } 
        catch (SQLException ex) {
              System.out.println(ex.getMessage())   ;     
}
       }

如果那肯定是一个 int 使用 int journalNo = Integer(ObjectValue);

否则将其转换为字符串,然后再转换为整数。在这种情况下,您将能够捕获 NumberFormatException。

对象到字符串:

String journalNumber = objectValue.toString();

字符串转整数:

int journalNumberAsInt = Integer.parseInt(journalNumber);

如果你想从 String 解析 int 你应该使用 Integer.parseInt() : https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#parseInt(java.lang.String)