aspose file tools*
The moose likes JSP and the fly likes problem in browsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "problem in browsing" Watch "problem in browsing" New topic
Author

problem in browsing

jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
some problem with this code:
written a code for browsing the records..
<%@ page language="java" import="java.sql.*,java.io.*,java.util.*,consultancy" %>
<%
Connection con=null;
java.sql.Statement stmt=null;
ResultSet rs=null;
boolean y=false;
int i;
boolean isRecord=false;
String xy=(String)session.getAttribute("y");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
out.println("1");
con=DriverManager.getConnection("jdbc dbc:mech_iit");
out.println("2");
stmt=con.createStatement();
out.println("3");
int count=0;
rs=stmt.executeQuery("select * from consultancy_projects where user_login='"+xy+"' order by consultancy_id");
out.println("4");
Vector vRecord=new Vector();
out.println("5");
while(rs.next())
{
out.println("6");
isRecord=true;
consultancy c=new consultancy();
c.setProject_Title(rs.getString("project_title"));
c.setClient(rs.getString("client"));
c.setOutlay(rs.getString("outlay"));
c.setConsultant_Name(rs.getString("consultant_name"));
c.setOther_Consultants(rs.getString("other_consultants"));
c.setYear(rs.getInt("year"));
vRecord.addElement(c);
}
out.println("7");
if(!isRecord)
{
%>
<jsp:forward page="no_records.jsp" />
<%
out.println("8");
return;
}
else
{
out.println("9");
session.setAttribute("Records", vRecord);

%>
<jsp:forward page="browse_consultancy_projects.jsp?RecordCount=5"/>

<%
out.println("10");
}
}
catch(Exception ie)
{
System.out.println("ie");
}
rs.close();
stmt.close();
con.close();
%>

the above should forward the page to browse .jsp page if a record is found else to the no_records found page.
my browse page is like this:
String xy=(String)session.getAttribute("y");

String sRecordCount=(String)request.getParameter("RecordCount");
int iRecordCount=Integer.parseInt(sRecordCount);
Vector vRecords=(Vector)session.getAttribute("Records");
int iNo_Of_Records=vRecords.size();
%>
<table border="1" cellpadding="1" cellspacing="1">

<td>Title</td>
<td>Client </td>
<td>Outlay</td>
<td>Consultant</td>
<td>Other Consultants</td>
<td>Year</td>
</tr>
<tr>
<%
for(int i=(iRecordCount-5);i<iRecordCount;++i)
{
if(i>=iNo_Of_Records)
break;
consultancy ob =(consultancy)vRecords.elementAt(i);
%>
<td> <%=ob.getProject_Title()%></td>
<td> <%=ob.getClient()%></td>
<td> <%=ob.getOutlay()%></td>
<td> <%=ob.getConsultant_Name()%></td>
<td> <%=ob.getOther_Consultants()%></td>
<td><%= ob.getYear() %></td>

</tr>
<%
}
%>


</table>
<%
if(iRecordCount>5)
{
%>
<a
href='browse_consultancy_projects.jsp?RecordCount=<%=(iRecordCount-5)%>'>Previous</a>
<%
}
%>
<%
if(iRecordCount<iNo_Of_Records)
{
%>
<a href='browse_consultancy_projectsjsp?RecordCount=<%=(iRecordCount+5)%>'>Next</a>
<%
}
%>
</tr>

the problem is that the fetch page doesnt forward the page to the browse .jsp page even when the records are found..
goes to the catch block and throws an exception..
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Can you also provide us your exception stack trace?
Thanks.
Nick.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Also, seems this is incorrect.

You should use:
<jsp:forward page="browse_consultancy_projects.jsp>
<jsp:param name="RecordCount" value="5"/>
</jsp:forward>
Nick.
jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
Hi Nicholas,
tried changing the jsp:forward bt that doesnt help..
the jsp page prints the following exception:
Exception...java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
any clues??
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 641
Nicholas,
I dont think any thing wrong with jsp:forward..it shoud work as far as get method is used..
Jyotsana..make sure calls to rs.getString("column name") are in exact order as the are feched in query...
say for example your query is select name,id,age from sonso"
then rs.getString() must be in same order(At least for driver,which you are using jdbodbc..)
i.e rs.getString("name");
rs.getString("id");
rs.getString("age");
if you say rs.getString("id") and then rs.getString("name"); you will end up with "java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
"
Cheers
Praful
cheers
Praful
[ March 11, 2004: Message edited by: Praful Thakare ]

All desirable things in life are either illegal, banned, expensive or married to someone else !!!
jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
Hey!!
Thanks Praful ! Well, the solution u offered worked..That was quite a new thing to learn..
Cheers to u too!
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
It's a restriction in the very old driver you're using.
It supports only reading of columns in the same order they exist in the table (and you can probably only read each column once).


42
 
wood burning stoves
 
subject: problem in browsing