Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error shows while retreving data from database

 
Harshal Gurav
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In my searchquestionid,jsp page I am try to showing data of one column i.e. description available in table name questioneid in tabular format. This page shows all word in that is in particular column. I am Using Form name as reference for next page i.e. updatequestionid.jsp to retrieve the all data related to that row showing in previous jsp page .but when I trying to display all field in that row I get only the first word of description column .
E.G. in searchquestionid.jsp page description column=�here is a test page�
But updatequestionid.jsp showing the same column =�here�
Here is my searchquestionid.jsp
<blockquote>code:
<pre name="code" class="core"> <%@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>SEARCH-QUESTION-ID</title>
</head>
<body>
<form name="searchquestion" action="questionidupdate.jsp" method="POST">

<table border="1" width="100">
<thead>
<tr>
<th>Seach Question-id</th>
</tr>
</thead>
<tbody>
<tr>
<td><b>Question-Id:</b> </td>
<td><select name="question">
<% 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();
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 align="center">
<td><input type="submit" value="Submit" name="submit" /></td>
</tr>

</tbody>
</table>


</form>
</body>
</html>
</pre>
</blockquote>

and here is updatequestionid.jsp:
<blockquote>code:
<pre name="code" class="core">
<%@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>QUESTION-ID-UPDATE</title>
</head>
<body>
<form name="searchgroup" action="questionidupdateok.jsp" method="POST">

<table border="1">
<%
String QUESTIONID=request.getParameter("question");
try {

Connection connection = null;
Statement st = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mynewdatabase","root", "root123");
st=connection.createStatement();

rs = st.executeQuery("select Questionid,Description from questionid where Questionid='"+QUESTIONID+"'");

%>

<tbody>
<tr><thead>
<tr>
<th><center>MODIFY Question-Id</center></th>
</tr>
</thead>
<td>Question-Id</td> <%
while (rs.next()) {
%>
<td><input type="text" name="id" value=<%=rs.getString("Questionid")%> size="20" /> </td>
<TR><TD>Desription</TD>
<TD><input type="text" name="descr" value=<%=rs.getString("Description")%> size="100" /></TD>
</TR>
</tr>
<tr>
<td><input type="submit" value="CHANGE" name="submit" /></td>
<td><input type="reset" value="RESET" name="res" /></td>
</tr>
</tbody>

<% } %>

<%

rs.close();
st.close();

} catch (Exception ex) {
out.println(ex.getMessage());

%>
<%
out.println("Unable to connect to database.");
}
%>

</table>
</form>
</body>
</html>
</pre>
</blockquote>
Any suggestion is highly appreciated.
Thanks and regards
Harshal
 
Jigar Naik
Ranch Hand
Posts: 761
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Missing quote

<blockquote>code:
<pre name="code" class="core"><TD><input type="text" name="descr" value="<%=rs.getString("Description")%>" size="100" /></TD></pre>
</blockquote>

should be value = "<%= ... %>"
instead of value = <%= ... %>
 
Harshal Gurav
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your suggestion.
Thanks and Regards
Harshal
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is too unreadable, so I did not get the exact problem.Please try to post the problem code fragment.
But one thing is you have mixed up the business logic with the view.
Consider separating it.

Looks like I took too long to reply
[ July 15, 2008: Message edited by: Amit Ghorpade ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic