• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in browsing

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you also provide us your exception stack trace?
Thanks.
Nick.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
jyotsana dang
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey!!
Thanks Praful ! Well, the solution u offered worked..That was quite a new thing to learn..
Cheers to u too!
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Where does a nanny get ground to air missles? Protect this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic