4
Contributors
6
Replies
10
Views
7 Years
Discussion Span
Last Post by Member 784740
0

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

Start a new thread and post some code

-1

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);
}

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

Votes + Comments
Total rubish, if you want to provide code samples you better be sure they are programmatically correct...
0

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

0

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>
0

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">
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.