Note that there are some explanatory texts on larger screens.

plurals
  1. POcan't print the request.getparameter value in jsp page
    primarykey
    data
    text
    <p>i am new to jsp i try to print a my database value in my jsp page, the below program work fine while i directly print the s1="january" and s2="2012" value,both datatype VARCHAR</p> <pre><code>String QueryString = "SELECT reading,totalcost,paiddate,receiptnumber FROM userseven WHERE readingmonth = '"+s1+"' AND readingyear= '"+s2+"'"; </code></pre> <p>if i try to print my request.getparameter("t1")( t1 contain january ) value request.getparameter("t2");(t2 contain 2011)</p> <p>it won't print any think,</p> <pre><code>String QueryString = "SELECT reading,totalcost,paiddate,receiptnumber FROM userseven WHERE readingmonth = '"+s11+"' AND readingyear= '"+s22+"'"; &lt;body&gt; &lt;form action="yeardb.jsp"&gt; &lt;table border="1" &gt; &lt;tr&gt; &lt;td&gt;Select Year&lt;/td&gt; &lt;td&gt; &lt;select name="t1"&gt; &lt;option value="2013"&gt;2013&lt;/option&gt; &lt;option value="2012"&gt;2012&lt;/option&gt; &lt;option value="2011"&gt;2011&lt;/option&gt; &lt;option value="2010"&gt;2010&lt;/option&gt; &lt;/select&gt; &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; &lt;tr&gt;&lt;td&gt;Select Month:&lt;/td&gt; &lt;td&gt; &lt;select name="t2"&gt; &lt;option value="january"&gt;JANUARY&lt;/option&gt; &lt;option value="march"&gt;March&lt;/option&gt; &lt;option value="may"&gt;May&lt;/option&gt; &lt;option value="july"&gt;JULY&lt;/option&gt; &lt;option value="aug"&gt;AUGUEST&lt;/option&gt; &lt;option value="oct"&gt;OCTOBER&lt;/option&gt; &lt;option value="dec"&gt;DECEMBER&lt;/option&gt; &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; &lt;input type= "submit" value="submit" &gt; &lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; yeardb.jsp ******** &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;%@page import="com.mysql.jdbc.Driver"%&gt; &lt;%@ page import="java.sql.*" %&gt; &lt;%@ page import="java.io.*" %&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;display data from the table using jsp&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;welcome&lt;/h1&gt; &lt;% String s11=request.getParameter("t1"); String s22=request.getParameter("t2"); String s1="january"; String s2="2011"; out.print("i am String"+s11); out.print("i am String"+s22); out.print("outside try"); try { out.print("inside try"); String connectionURL = "jdbc:mysql://localhost:3306/horizontal"; Connection connection = null; Statement statement = null; ResultSet rs = null; Class.forName("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager.getConnection(connectionURL, "root", "root"); statement = connection.createStatement(); out.print("before query"); String QueryString = "SELECT reading,totalcost,paiddate,receiptnumber FROM userseven WHERE readingmonth = '"+s1+"' AND readingyear= '"+s2+"'"; out.print("after query"); rs = statement.executeQuery(QueryString); </code></pre> <p>%></p> <pre><code> &lt;TABLE cellpadding="15" border="1" style="background-color: #ffffcc;"&gt; &lt;% out.print("outside while"); while (rs.next()) { out.print("inside while"); %&gt; &lt;TR&gt; &lt;TD&gt;&lt;%=rs.getString(1)%&gt;&lt;/TD&gt; &lt;TD&gt;&lt;%=rs.getString(2)%&gt;&lt;/TD&gt; &lt;TD&gt;&lt;%=rs.getString(3)%&gt;&lt;/TD&gt; &lt;TD&gt;&lt;%=rs.getString(4)%&gt;&lt;/TD&gt; &lt;/TR&gt; &lt;% } %&gt; &lt;% // close all the connections. rs.close(); statement.close(); connection.close(); } catch (Exception ex) { %&gt; &lt;/font&gt; &lt;font size="+3" color="red"&gt;&lt;/b&gt; &lt;% out.println("Unable to connect to database."); } %&gt; &lt;/TABLE&gt;&lt;TABLE&gt; &lt;TR&gt; &lt;button type="submit"&gt;&lt;-- back&lt;/button&gt;&lt;/TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;/font&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload