Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Tulasiram Mutyala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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);

}
%>

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did spaces get into your parameter names?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic