File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes displaying data from two table in single jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "displaying data from two table in single jsp page" Watch "displaying data from two table in single jsp page" New topic
Author

displaying data from two table in single jsp page

Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
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 ]
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

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.


[Servlet tutorial] [Servlet 3.0 Cook Book]
Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
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

Joined: May 29, 2008
Posts: 151
Hi,
The above error is solved with creation seprate resultset and statement object for each table.
Thanks for your co-operation.
Regards
Harshal
 
wood burning stoves
 
subject: displaying data from two table in single jsp page
 
Similar Threads
How to retrive data two times from database in sinble jsp page.
Error shows while retreving data from database
error showing while retrieving the data from drop down list
javax. servlet. Servlet Exception: java. sql. SQLException
showing variable field from database. table.