如標題所示,我已經盡力將用戶輸入與我的數據庫進行比較,它與真正的輸入一起工作。但是,當我的數據庫中不存在輸入時,我不知道我的下面的代碼中有什麼問題,請幫助。如何比較用戶輸入和我的數據庫在java
private class da implements ActionListener{
public void actionPerformed(ActionEvent e){
Connection con = null;
String url = "jdbc:mysql://localhost:3306/المكتبة";
String unicode = "?useUnicode=yes&characterEncoding=UTF-8";
try{
con = DriverManager.getConnection(url+unicode,"root","");
PreparedStatement upd = con.prepareStatement("SELECT * FROM library WHERE author =?'");
upd.setString(1,name.getText());
ResultSet rs = upd.executeQuery();
while(rs.next()){
String authorname = rs.getString("author");
String bookname = rs.getString("bookname");
String categort = rs.getString("category");
int isbn = Integer.parseInt(rs.getString("ISBN"));
String data = "اسم المؤلف: "+authorname+"\n"+"اسم الكتاب: "+bookname+"\n"+"التصنيف: "+categort+"\n"+"ISBN: "+isbn;
if(name.getText().equals(authorname))
txt.setText(data);
else
txt.setText("no matches");
它工作時輸入相等,但不能輸入時不匹配 – Forenkazan 2014-12-13 03:08:41