I want to know how to get integer value from input dailog box
和查询它的select语句 里面看起来我的错误输入框中键入按我下面的是对象,我不知道如何解析对象为整数,从而由SELECT语句 接受请告知如何处理的对象类型,以获得输入框的变量,并注入同进我的选择传球和分析对象输入对话框值到数据库表
私人无效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()) ;
}
}
THX @Nikitha我发现它不解析看起来里面的加号,用空格我删除空格,现在选择工作正常 –