I am tryin to fetch values from my sql database based on the inputs from a webpage using a select query. I have pasted the query and bit of the code below. The problem is that the query needs input for each and every variable to fetch data since I am using AND. if i dont input a certain value, It will not throw out any output. Please tell me how can I get data from the database even if some of the variables have empty strings.
String host = reqt.getParameter("hostname");
String uuid = reqt.getParameter("cinum");
String cdir = reqt.getParameter("custcode");
String customer = reqt.getParameter("custname");
String mgip = reqt.getParameter("mgmtip");
String cusip = reqt.getParameter("custip");
String bakip = reqt.getParameter("backip");
String ismtick = reqt.getParameter("ismticket");
String tickmean = reqt.getParameter("ticketmean");
String mgtlev = reqt.getParameter("mgmtlvl");
String ptchcat = reqt.getParameter("patchcat");
String ptchsc = reqt.getParameter("patchsch");
String vmsite = reqt.getParameter("site");
String vmcep = reqt.getParameter("cep");
String vmscope = reqt.getParameter("scope");
String os = reqt.getParameter("platform");
String plattype = reqt.getParameter("ostype");
Statement stmt = null;
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/CMS_SCS_PORTAL", "root", "test");
String sql = "Select * from inventory_table where ISNULL(hostname) = '"+host+"' AND ISNULL(uuid) = '"+uuid+"' AND ISNULL(cdir) = '"+cdir+"' AND ISNULL(customer) = '"+customer+"' AND ISNULL(management_ip) = '"+mgip+"' AND ISNULL(customer_ip) = '"+cusip+"' AND ISNULL(backup_ip) = '"+bakip+"' AND ISNULL(ism_ticket_state) = '"+ismtick+"' AND ISNULL(ticket_state_meaning) ='"+tickmean+"' AND ISNULL(management_level) = '"+mgtlev+"' AND ISNULL(patch_category) = '"+ptchcat+"' AND ISNULL(patch_schedule) = '"+ptchsc+"' AND ISNULL(host_site) = '"+vmsite+"' AND ISNULL(VM_Cep) = '"+vmcep+"' AND ISNULL(VM_Scope) = '"+vmscope+"' AND ISNULL(Operating_System) = '"+os+"' AND ISNULL(Operating_System_Type) = '"+plattype+"' LIMIT 10000";
stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql);