How to find an item in a MySQL database using Java
1,461 viewsHere's a method i wrote to find an item in a MySQL database and to show the found item. I wrote this class for someone so the text might be confusing =) details of this application + screenshot can be found here: http://www.engineeringserver.com/blog/2007/12/28/tenant-application/
JAVA:
-
public void findItemFromDatabase(){
-
boolean add = true;
-
int duplicate = 0;
-
try {
-
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
-
String queryCheckTenants = "select name from tenant";
-
while(resultCheck.next()){
-
if(resultCheck.getString("Name").equals(find)){
-
duplicate++;
-
}
-
}
-
if(duplicate>0){
-
resultBtn.setVisible(true);
-
resultFoundLbl.setText("Tendant found," + "\n" + "click detail(s) for more info.");
-
resultFoundLbl.setVisible(true);
-
searchBtn.setEnabled(false);
-
findTf.setEditable(false);
-
found = true;
-
add = false;
-
}
-
else{
-
resultBtn.setVisible(true);
-
resultBtn.setEnabled(true);
-
resultBtn.setText("Add tenant");
-
resultFoundLbl.setText("No match found, " +"\n" + "please try again or add new tenant.");
-
resultFoundLbl.setVisible(true);
-
searchBtn.setEnabled(false);
-
findTf.setEditable(false);
-
found = false;
-
add = true;
-
}
-
//obsolette
-
if (add){
-
}
-
if (!add){
-
}
-
e.printStackTrace();
-
e.printStackTrace();
-
e.printStackTrace();
-
e.printStackTrace();
-
}
-
}

(1 votes, average: 4 out of 5)










