I my web app, i have search fiedl where i get some string and a combo box. So, i am sending two arguments to the remote function.
I want to check the user input is not null and not empty. So, then i can construct a valid query.
public ArrayList findEmployees(String str, int dep)throws ClassNotFoundException, SQLException{
System.out.println("List IN");
ArrayList list = new ArrayList();
java.sql.Statement stmt;
java.sql.ResultSet rs;
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/general";
java.sql.Connection con = DriverManager.getConnection(url, "root", "1234");
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
stmt = con.createStatement();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String qry = "SELECT * FROM PERSON ";
String werstr = "WHERE";
if(str!= null && str != "**here i want to check the 'str' is empty or not." )
{
qry += werstr + " NAME LIKE '%"+str+"%'";
System.out.println(qry);
werstr = "AND";
}
if(dep != 0)
{
qry += werstr + "dept="+dep;
}
qry += ";";
System.out.println(qry);
rs = stmt.executeQuery(qry);
while (rs.next()) {
Employee employee = new Employee();
String name = rs.getString(2);
employee.setName(name);
int id = rs.getInt(1);
employee.setId(id);
int dept = rs.getInt(4);
employee.setDept(dept);
int age = rs.getInt(3);
employee.setAge(age);
list.add(employee);
}
System.out.println("List Out");
return list;
}
Any suggestons