Hi I need code for searching the records in a table for specified conditions using jsp

Recommended Answers

All 6 Replies

Hi I need code for searching the records in a table for specified conditions using jsp

Start a new thread and post some code

hai,

searchform.jsp
<input type = "text" name ="record">
2. click search button
3. action = "searchresult.jsp"


searchresult.jsp

String value = request.getParameter("record");
// connect databases;
// give sql query :

String sql = select * from empdetails where empno = '"+value+"';

ResultSet rs = st.executeQuery(sql);
while(rs.next())
{
String empname = rs.getString("empname");
String empid = rs.getString("empid");
// etc
out.println(empname);
out.println(empid);
}
commented: Total rubish, if you want to provide code samples you better be sure they are programmatically correct... -2

hai,

searchform.jsp
<input type = "text" name ="record">
2. click search button
3. action = "searchresult.jsp"


searchresult.jsp

String value = request.getParameter("record");
// connect databases;
// give sql query :

String sql = select * from empdetails where empno = '"+value+"';

ResultSet rs = st.executeQuery(sql);
while(rs.next())
{
String empname = rs.getString("empname");
String empid = rs.getString("empid");
// etc
out.println(empname);
out.println(empid);
}

Totally wrong. Don't do database connections inside jsp. Use servlets instead

Hey, A have a similar question I want do search my form using three input fields and a submit button, than I want to filter my list of patients using method GET. Can you show my how to change this code to do that?

<body>
        <form action='"ShowPatientList.do?imie="+ ' name="patientDetailsForm" method = "GET">
            <p>Imię     <input id ="imie" name = "Imie" value = ""></p>
            <p>Nazwisko <input id ="nazwisko" name = "Nazwisko" value = ""></p>
            <p>Pesel    <input id ="pesel" name = "Pesel" value = ""></p>
            <input id ="subbutton" type = "submit" name="Wyszukiwanie" value = "Szukaj">
            <c:forEach var="patient" items="${allPatients}">
                <p  onmouseover="style.backgroundColor='blue', style.cursor='pointer', style.width='320px'"
                    onmouseout="style.backgroundColor='white'"
                    onclick='method = "GET", window.location="ShowPatientDetail.do?guid="+<c:out value="${patient.guid}"/>'>
                    <c:out value="${patient.name}"/>
                    <c:out value="${patient.surname}"/>
                    <c:out value="${patient.pesel}"/>
                </p>
            </c:forEach>
        </form>
    </body>

Hey, A have a similar question I want do search my form using three input fields and a submit button, than I want to filter my list of patients using method GET. Can you show my how to change this code to do that?

<body>
        <form action='"ShowPatientList.do?imie="+ ' name="patientDetailsForm" method = "GET">
            <p>Imię     <input id ="imie" name = "Imie" value = ""></p>
            <p>Nazwisko <input id ="nazwisko" name = "Nazwisko" value = ""></p>
            <p>Pesel    <input id ="pesel" name = "Pesel" value = ""></p>
            <input id ="subbutton" type = "submit" name="Wyszukiwanie" value = "Szukaj">
            <c:forEach var="patient" items="${allPatients}">
                <p  onmouseover="style.backgroundColor='blue', style.cursor='pointer', style.width='320px'"
                    onmouseout="style.backgroundColor='white'"
                    onclick='method = "GET", window.location="ShowPatientDetail.do?guid="+<c:out value="${patient.guid}"/>'>
                    <c:out value="${patient.name}"/>
                    <c:out value="${patient.surname}"/>
                    <c:out value="${patient.pesel}"/>
                </p>
            </c:forEach>
        </form>
    </body>

Start a new thread with your question.
Also my Struts 1.x are a little rusty so I can not provide much help. What I can tell you is this:
Why do you write the action like this:
'"ShowPatientList.do?imie="+ '

It should be like this:
action="ShowPatientList.do"

The rest of the parameters will be passed with the request once you submit the form. All you have to do with the onclick (which I believe should be onchange) is to submit the form:

document.getElementById("patientDetailsForm").submit();

To do that you need to add an id as well:

<form action="ShowPatientList.do" id="patientDetailsForm" name="patientDetailsForm" method = "GET">
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.