• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);

}
%>

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what's problem? The description in your subject is not sufficient.
 
Tulasiram Mutyala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did spaces get into your parameter names?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic