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

Invalid Cursor State

mocca az
Ranch Hand

Joined: Mar 07, 2001
Posts: 93
Greetings!!!
I have listing.jsp where i display all the records from the DB.
JOBCODE is displayed as a link and onClick is calling detail.jsp?par=somenumber, so i am passing par=111 to a detail.jsp. This page fetches passed jobcode and it supposed to bring all the details for that jobcode that are in DB. However that is not happening. Error i am getting is javax.servlet.ServletException: [Microsoft][ODBC Driver Manager] Invalid cursor state
Below is the detail.jsp. Same error occurs even if i hardcode jobcode.
Hopefully someone can help me out. Sorry if i am not clear enough. It's 2:30 AM, and my eyes are leaking out.
<%@ page
language = "java"
import = "java.sql.*"
%>

<%!
String jobCode, position, location, datePosted, desc, skills;
String empType, duration, agent, phone, email;
Connection connection;
Statement statement;
ResultSet rs;
%>
<%
jobCode = request.getParameter("jobcode");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

connection = DriverManager.getConnection("jdbc dbc:empagency","", "");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT POSITION, LOCATION, DATEPOSTED, DESCRIPTION, SKILLS, EMPTYPE, DURATION, AGENT, PHONE, EMAIL FROM JOBS WHERE JOBCODE = ' + jobCode + '");
}
catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td bgcolor="#8585AD">
<%
//jobCode = rs.getString("JOBCODE");
position = rs.getString("POSITION");
location = rs.getString("LOCATION");
datePosted = rs.getString("DATEPOSTED");
desc = rs.getString("DESCRIPTION");
skills = rs.getString("SKILLS");
empType = rs.getString("EMPTYPE");
duration = rs.getString("DURATION");
agent = rs.getString("AGENT");
phone = rs.getString("PHONE");
email = rs.getString("EMAIL");

%>
<table width="100%" border="0" cellspacing="1" cellpadding="0" height="99">
<tr>
<td bgcolor="#6666CC" height="144">
<table width="100%" border="0" cellspacing="1" cellpadding="2" height="161" class="jobsTable">
<tr bgcolor="#99CCFF">
<td width="18%" height="32"><b><%= jobCode %></b></td>
<td width="58%" height="32"><b><%= position %></b></td>
<td width="24%" height="32"><b><%= location %></b></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="11" width="18%" bgcolor="#FFCC00"><b>Date Posted:</b></td>
<td colspan="2" height="11" bgcolor="#FFFFCC"><%= datePosted %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="11" width="18%" bgcolor="#FFCC00"><b>Description:</b></td>
<td colspan="2" height="11" bgcolor="#FFFFCC"><%= desc %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="9" width="18%" bgcolor="#FFCC00"><b>Skills:</b></td>
<td colspan="2" height="9" bgcolor="#FFFFCC"><%= skills %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="18%" height="8" bgcolor="#FFCC00"><b>Emp. Type:</b></td>
<td colspan="2" height="8" bgcolor="#FFFFCC"><%= empType %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="18%" height="2" bgcolor="#FFCC00"><b>Duration:</b></td>
<td colspan="2" height="2" bgcolor="#FFFFCC"><%= duration %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="18%" height="7" bgcolor="#FFCC00"><b>Contact Agent:</b></td>
<td colspan="2" height="7" bgcolor="#FFFFCC"><%= agent %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="18%" height="2" bgcolor="#FFCC00"><b>Telephone:</b></td>
<td colspan="2" height="2" bgcolor="#FFFFCC"><%= phone %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="18%" height="2" bgcolor="#FFCC00"><b>E-mail Resume:</b></td>
<td colspan="2" height="2" bgcolor="#FFFFCC"><a href="mailto:<%= email %>?Subject=Job Code:<%= jobCode %> - <%= position %>"><%= email %></a></td>
</tr>
</table>
</td>
</tr>
</table>
<%
rs.close();
%>
</td>
</tr>
</table>

Greatly appreciated,
moe, phx
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

Your error message is coming from the Microsoft ODBC driver. The JDBC-ODBC bridge isn't thread-safe, so that MIGHT be your problem.
Then again, if I really wanted to inflict pain on someone, I'd make them work with ODBC at 2am even without Java !


Customer surveys are for companies who didn't pay proper attention to begin with.
mocca az
Ranch Hand

Joined: Mar 07, 2001
Posts: 93
Thank you Tim.
One way or the other but i got it to work somehow.
m, phx
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The first row in a ResultSet is always empty.
When you want to retrieve the results from a select returning a single result you have to make sure it has returned at least one result by attempting to push the cursor forward:

Same for a query that return multiple rows except that you use while instead of if.
Dave.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalid Cursor State