• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

displaying data from two table in single jsp page

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to display the data of one column from two table named questioned and groupid in my jsp page. But the error occurring at the marked line is: can not find Symbol option, ; expected like:
Here is an my code:
<blockquote><font size="1" face="Verdana, Arial">code:</font><hr><pre name="code" class="core"><font size="2">
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language ="java" %>
<%@ page import="java.sql.*, javax.sql.*, javax.naming.*,java.io.*,java.util.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">;

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ADD EVENT</title>
</head>
<body>
<form name="addevent" action="addeventok.jsp" method="POST">
<table border="1" width="100">
<thead>
<tr>
<center>ADD-EVENT</center>
</tr>
</thead>
<tbody>
<tr>
<td><B>EVENT-NAME</B></td>
<td><input type="text" name="name" value="" size="255" /></td>
</tr>
<tr>
<td><b>EVENT-TYPE</b></td>
<td><select name="eventtype">
<option><b>PUBLISH</b></option>
<option><B>UNPUBLISH</B></option>
</select></td>
</tr>
<tr>
<td><B>QUESTION-TYPE</B></td>
<%
Connection connection = null;
Statement st = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mynewdatabase","root", "root123");
st=con.createStatement();
%>
<td><select name="question">
<%
try {
rs = st.executeQuery("Select * from questionid");
while (rs.next())
{

<option value = "<%=rs.getString("Questionid")%>" ><%=rs.getString(2)%></option>
<%
}

}
finally
{
if (rs != null)
{
rs.close();
rs = null;
}
if (st != null)
{
st.close();
st = null;
}

}

%>
%>
</select>
</td>
</tr>
<tr>
<td><B>TARGET-GROUP</B></td>
<td><select name="group">
<%

try {
rs = st.executeQuery("Select * from groupid");
while (rs.next())
{
%>
<option value = "<%=rs.getString("groupid")%>" ><%=rs.getString(2)%></option>
<%
}

}
finally
{
if (rs != null)
{
rs.close();
rs = null;
}
if (st != null)
{
st.close();
st = null;
}

}

%>

</select>
</td>
</tr>
<tr>
<td>USERR IDENTITY</td>
<td><select name="identity">
<option>Anonymous</option>
<option>Identify</option>
</select></td>
</tr>
<tr>
<td><input type="submit" value="ADD" name="add" /></td>
<td><input type="reset" value="RESET" name="reset" /></td>
</tr>
</tbody>
</table>

</form>
</body>
</html>
</font></pre><hr></blockquote>
Any suggestion is highly appreciated.
Thanks and Regards
Harshal
[ July 16, 2008: Message edited by: Harshal Gurav ]
 
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is syntax error in your JSP
<blockquote>code:
<pre name="code" class="core">
while (rs.next())
{

<option value = "<%=rs.getString("Questionid")%>" ><%=rs.getString(2)%></option>
<%
}
</pre>
</blockquote>

You need to close the scriptlet.
put %> before option tag.
 
Harshal Gurav
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sudhir,
Thanks for your post.
After modifing it now shows error like:
java.lang.NullPointerException
org.apache.jsp.Event.addevent_jsp._jspService(addevent_jsp.java:152)
at the line:
<blockquote>code:
<pre name="code" class="core"> <select name="group">
<%
try {
rs = st.executeQuery("Select * from groupid"); while (rs.next())
{
%>
</pre>
</blockquote>

I am trying to display the data from one column in table groupid
Thanks and Regards
Harshal
 
Harshal Gurav
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The above error is solved with creation seprate resultset and statement object for each table.
Thanks for your co-operation.
Regards
Harshal
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic