aspose file tools*
The moose likes JSP and the fly likes Error  shows while  retreving data from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Error  shows while  retreving data from database " Watch "Error  shows while  retreving data from database " New topic
Author

Error shows while retreving data from database

Harshal Gurav
Ranch Hand

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

Joined: Dec 12, 2006
Posts: 759
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 = <%= ... %>


Jigar Naik


Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Thank you very much for your suggestion.
Thanks and Regards
Harshal
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

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 ]

SCJP, SCWCD.
|Asking Good Questions|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error shows while retreving data from database