*
The moose likes JSP and the fly likes Jdbc query problem when passing request.getParameter() if parameter is string value only Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Jdbc query problem when passing request.getParameter() if parameter is string value only" Watch "Jdbc query problem when passing request.getParameter() if parameter is string value only" New topic
Author

Jdbc query problem when passing request.getParameter() if parameter is string value only

Tulasiram Mutyala
Greenhorn

Joined: Apr 19, 2013
Posts: 3
Index.jsp:
-------------

<form action="first.jsp" method="post" name="f1" onsubmit="return validate1()">


<%@include file="db.jsp" %>
<%

Statement st = con.createStatement();
ResultSet results = st.executeQuery("SELECT * FROM places");
while(results.next()){
String id = results.getString(1);
String name = results.getString(2);
%>

<option value="<% out.println(name); %>">
<%=name%>
</option>


<%} results.close(); %>
</select><br>



   To:          <select name="sel2" style="width: 100px"><option value="">To---></option>
<%
ResultSet results1 = st.executeQuery("select * from places ");
while(results1.next()){
String id1 =results1.getString(1) ;
String name1 = results1.getString(2);
%>

<option value="<% out.println(name1); %>">
<%=name1%>
</option>

<%} results1.close(); %>
</select><br>

   Date:       <input type="text" name="date" class="tcal" value="" style="width: 80px"><br>
<center><input type="submit" value="Findflights" name="s1" ></center>

First.jsp:
----------
String sel1 = request.getParameter("sel1");
String sel2 = request.getParameter("sel2");
String myParameter3 = request.getParameter("date");

sel1 ="'"+sel1 +"'";

if(myParameter7.equalsIgnoreCase("Findflights") )

{%>

<%@include file="db.jsp" %>

<% Statement st5=con.createStatement();

ResultSet resultset5= st5.executeQuery("Select * from places where place="+sel1);

while(resultset5.next())
{
String namep=resultset5.getString("palce");

out.println(namep);

}
%>

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

So what's problem? The description in your subject is not sufficient.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tulasiram Mutyala
Greenhorn

Joined: Apr 19, 2013
Posts: 3
thanks for the reply.

In my index.jsp page i am getting city names from database using select box and Enduser select City names from select box and these values are passed to next page ie first.jsp and i am getting those values using request.getParameter("Selectboxname") and i am able to see those city name values in this page and passing them to sql select query upto this everything is fine and query is executed but problem is i am unable to see result of the query.And i didn't get any syntax error and i am getting blank page with no output.And the problem is only when i am passing string values ie cityname And when i am passing city id ie int type every thing is fine.
Tulasiram Mutyala
Greenhorn

Joined: Apr 19, 2013
Posts: 3
solved the problem is because of name spaces in request.getparameter(""); for that i used String s= request.getparameter("").trim().
Here trim() removes unwanted spaces.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

How did spaces get into your parameter names?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jdbc query problem when passing request.getParameter() if parameter is string value only