我正在尝试将类searchitem
中名为Query
的方法调用到名为Search的jbutton,它将搜索数据库中表项的所有详细信息并将其显示在jtextfields中。下面是Query类中的searchitem
方法。
public ResultSet searchitem() {
try {
String sql = "select * from tblitem";
stmt = conn.connect.createStatement();
rs = stmt.executeQuery(sql);
return rs;
} catch (SQLException ex) {
System.out.println("SQL Exception in Seach Book "+ex.getMessage());
JOptionPane.showMessageDialog(null, "Error in Retriving Book Information", "Error", JOptionPane.ERROR_MESSAGE);
Logger.getLogger(Query.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
这是jbutton中的代码。
try {
String id, nme,cos,pr,available,sid,search;
search= stf1.getText();
if(search.length()!=5 || !search.toLowerCase().startsWith("i")){
JOptionPane.showMessageDialog(null, "Incorrect Item ID \nItem ID should start with 'i' and 5 characters should be used ", "Error", WIDTH);
}
else{
Query query = new Query();
rs = query. searchitem(search);
rs.next();
id = rs.getString(1);
nme= rs.getString(2);
cos = rs.getString(3);
pr = rs.getString(4);
available = rs.getString(5);
sid = rs.getString(6);
boolean availablity = Boolean.valueOf(available);
etf1.setText(id);
etf2.setText(nme);
etf3.setText(cos);
etf4.setText(pr);
ecb1.setSelected(availablity);
etf5.setText(sid);
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Item not Available. \nEnter an existing Item ID", "Unavailable", JOptionPane.ERROR_MESSAGE);
System.out.println("SQL Exception in retriving Item details");
Logger.getLogger(Item.class.getName()).log(Level.SEVERE, null, ex);
}
}
但我在第rs = query. searchitem(search);
行说
答案 0 :(得分:0)
您的方法segnature没有参数:public ResultSet searchitem() {
。
但你用一个参数rs = query. searchitem(search);
来称呼它。那不合适。
因此,在调用函数时删除参数,或者实现一个期望一个参数类型正确的函数