how to search for string using LIKE operator instead of integer?

how to search for string using LIKE operator instead of integer?

dear sir, i have 3 jsp files, first "index.jsp", "dbtable.jsp", and "table2.jsp". what my code does is goes to the "index.jsp" file and let the user enters an ID to search for itemid, then it shows "dbtable.jsp" file with 3 columns of itemid, itemname, and description. the itemid is in hyperlink so when the user click on of them it'll go to the third file which is "table2.jsp" which will show the details of that hyperlink. note that "dbtable" and "table2" have relations in itemid. however, what i want to do is i want the user to search for the itemname instead of the itemid, and i want the itemname column to be in hyperlink not itemid. and do the same thing by clicking on the hyperlink on itemname column and show "table2" details. in other words, my "dbtable.jsp" query should be like this (select * from items where itemname LIKE '"+id). and my detail file "table2.jsp" should be (select * from itemdetails where item_id ='"+id"') or something like that. but as you see, first query needs integer and second one needs string. i hope you get the picture.

there are the codes:

***"index.jsp"***

    <html>
    <form method="post" action="dbtable.jsp">
    Enter id: <input type="text" name="id">
    <input type="submit" value="Search">
    </form>
    </html>

***"dbtable.jsp"***

    <%@page import="java.sql.*"%>
    <html>
    <table border="1">
    <%
    try{
    String v=request.getParameter("id");
    int id=Integer.parseInt(v);
    Class.forName("com.mysql.jdbc.Driver").newInstance();  
     Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
    Statement st=con.createStatement();
    ResultSet rs=st.executeQuery("Select * from items where itemid="+id+"");
    while(rs.next()){
        %>
    <tr>
<td><a href="table2.jsp?id=<%=rs.getString("itemid")%>"><%=rs.getString("itemid")</a></td>
<td><%=rs.getString("item")%></td>
<td><%=rs.getString("description")%></td></tr>
    <%
    }
    }
    catch(Exception e){
        System.out.println(e);
    }
    %>
    </table>
    </html>

***"table2.jsp"***

    <%@page import="java.sql.*"%>
    <html>
    <table border="1">
    <%
    String v=request.getParameter("id");
    int id=Integer.parseInt(v);
    Class.forName("com.mysql.jdbc.Driver").newInstance();  
     Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
    Statement st=con.createStatement();
    ResultSet rs=st.executeQuery("Select * from subinventory where itemid="+id+"");
    while(rs.next()){
        %>
    <tr>
<td><%=rs.getInt("itemid")%></td>
<td><%=rs.getInt("subinventoryid")%></td>
<td><%=rs.getInt("quantity")%></td></tr>
    <%
    }
    %>
    </table>
    </html>
View Answers

June 5, 2011 at 4:19 PM

modify "table2.jsp"

<%@page import="java.sql.*"%>
        <html>
        <table border="1">
        <%
        try{
        String v=request.getParameter("id");
        int id=Integer.parseInt(v);
        Class.forName("com.mysql.jdbc.Driver").newInstance();  
         Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery("Select * from items where itemid="+id+"");
        while(rs.next()){
            %>
        <tr>
    <td><a href="table2.jsp?id=<%=rs.getString("itemid")%>"><%=rs.getString("itemid")%></a></td><td><%=rs.getString("item")%></td>
    <td><%=rs.getString("description")%></td></tr>
        <%
        }
        }
        catch(Exception e){
            System.out.println(e);
        }
        %>
        </table>
        </html>

Ads









Related Tutorials/Questions & Answers:
how to search for string using LIKE operator instead of integer?
Hibernate HQL query by using like operator.
Advertisements
how to find the sum of integers in a string of sentence in java
like operator
Search string using substring
Mysql Like Operator
Mysql Like Operator
LIKE Operator
Integers separated by a ", " in a string
PHP SQL LIKE Operator
LIKE Operator
PHP SQL LIKE Operator
SQL AND Like Operator
JAVA leftshift operator add 1 instead of 0
how to search the string arraylist contains database rows?
How to perform search using AJAX?
How to split string in Java using comma?
how to count words in string using java
SQL AND Like Operator
how to write a program to search a record using mvc2
How to write a search functionality using javascript/jquery
Mysql Date like
How to create binary search tree using an array?
How to using Binary Search Array Java ?
how to find [count the number of integers whose value is less than the average value of the integers]
integers
INTEGERS
Using [] operator of EL with an Array
How ro convert char into string using recursive function in c#??
how to convert string to char array in java without using tochararray
Drop down for search textbox like google search
integers
How to search the selected item in row table using radia button in JSP?
How to declare a Combobox without using a string in its declaration?
adding two numbers with out using any operator
how to re size image proportionately using java for different images like jpeg, png, gif.
Using of [] operator of EL with the Map
Mysql Like Operator
Mysql Like Operator
string palindrom using vbscript?
how to get data using dropdownlist, textbox and search button in jsp
Java Compare String (== operator)
how to devide a web page into parts and setting the targets like frames but without using frames
NSMutableArray Search String
ModuleNotFoundError: No module named 'string-path-search'
ModuleNotFoundError: No module named 'data-string-search'
convert date into String like 9-10-2012 into nine october two thousand twelve
String Reverse Using StringUtils
JPA CriteriaBuilder - How to use ?IN? comparison operator
How to use OR operator in hibernate Detached criteria query?

Ads