Hi All,
I tried the following code to run in jsp using Tomcat 4, the following code took from web.
Code:
<%@ page import="sun.jdbc.rowset.CachedRowSet" %>
<HTML>
<HEAD>
<jsp:useBean id="Contacts" class="sun.jdbc.rowset.CachedRowSet" scope="session">
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// initialize our CachedRowSet bean
Contacts.setUsername("sa");
Contacts.setPassword("");
Contacts.setUrl("jdbc:odbc:VFS");
Contacts.setCommand("SELECT name, telephone from Contacts");
Contacts.execute();
Contacts.first();
%>
</jsp:useBean>
<%
// get the servlet request object
javax.servlet.ServletRequest req = pageContext.getRequest();
// process updates
boolean updateRow = false;
String contactName = Contacts.getString(1);
String newValue = req.getParameter("ContactName");
if (( newValue != null) && (!newValue.equals( contactName ))) {
Contacts.updateString( 1,req.getParameter("ContactName"));
updateRow = true;
}
String contactPhone = Contacts.getString(2);
newValue = req.getParameter("ContactPhone");
if (( newValue != null) && (!newValue.equals(contactPhone))) {
Contacts.updateString( 2,req.getParameter("ContactPhone"));
updateRow = true;
}
if (updateRow) Contacts.updateRow();
// process navigation commands
if ( req.getParameter("next") != null ) {
if (! Contacts.next() ) Contacts.last();
} else if ( req.getParameter("prev") != null) {
if (! Contacts.previous()) Contacts.first();
} else if ( req.getParameter("save") != null) {
Contacts.acceptChanges();
} else if ( req.getParameter("insert") != null) {
Contacts.moveToInsertRow();
Contacts.updateString(1, "");
Contacts.updateString(2, "");
Contacts.insertRow();
Contacts.moveToCurrentRow();
Contacts.next();
} else if ( req.getParameter("delete") != null) {
Contacts.deleteRow();
if (!Contacts.next()) Contacts.last();
}
%>
<STYLE>
BODY { font-style: verdana }
</STYLE>
<TITLE>
CachedRowSetExample
</TITLE>
</HEAD>
<BODY BGCOLOR='lightgrey'>
<H2>Contacts</H2>
<FORM METHOD="POST">
<TABLE BORDER='0'>
<TR><TD>Name:</TD><TD>Telephone number:</TD></TR>
<TR>
<TD><INPUT TYPE='text'
NAME="ContactName"
VALUE='<%=Contacts.getString(1)%>' /></TD>
<TD><INPUT TYPE="text"
NAME="ContactPhone"
VALUE='<%=Contacts.getString(2)%>' /></TD>
</TABLE>
<INPUT TYPE="submit" NAME="prev" VALUE=" < "/>
<INPUT TYPE="submit" NAME="next" VALUE=" > "/>
<INPUT TYPE="submit" NAME="insert" VALUE="Insert"/>
<INPUT TYPE="submit" NAME="delete" VALUE="Delete"/>
<INPUT TYPE="submit" NAME="save" VALUE="Save"/>
Record <%=Contacts.getRow()%> of <%=Contacts.size()%>
</FORM>
</BODY>
</HTML>
When i run this program the following error occurred:
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
C:\Program Files\Apache Tomcat 4.0\work\localhost\web\CachedRowSetExample$jsp.jav a:3: Class sun.jdbc.rowset.CachedRowSet not found in import.
import sun.jdbc.rowset.CachedRowSet;
^
I added the rowset.jar file under WEB-INF/lib.
Where did i wrong in my code?
If anybody know the answer kindly post ur suggestion.
How to add the rowset.jar file in my WEB-INF/lib and how to call the class file in my application from rowset.jar? Is there any procedure to add the rowset.jar file in my application?
Thanks and Regards,
V. Prasath