Hi,
I have a servlet that creates and returns a Recordset. Does anybody have a little sample of how to reference the servlet is a jsp page to display the values from the recordset. The code is below
Thanks in advance.
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public class GetDataSample extends HttpServlet
{
/** Creates a new instance of the class */
public GetDataSample(HttpServletRequest request, HttpServletResponse response, JspWriter out)
throws UnavailableException
{
// set up some stuff if you need to here
}
public GetDataSample()
{
//default contstructor
}
public ResultSet getRecordSet() throws UnavailableException
{
String url = "jdbcdbc:NorthWindJava";
Connection con;
ResultSet rs;
String createString;
createString = "Select FirstName, LastName, Title, Address from employees";
Statement stmt;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
con = DriverManager.getConnection(url, "uid", "psw"
stmt = con.createStatement();
rs = stmt.executeQuery(createString);
stmt.close();
con.close();
return rs;
}
catch (Exception e)
{
throw new UnavailableException(e.getMessage());
}
}
}
I have a servlet that creates and returns a Recordset. Does anybody have a little sample of how to reference the servlet is a jsp page to display the values from the recordset. The code is below
Thanks in advance.
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public class GetDataSample extends HttpServlet
{
/** Creates a new instance of the class */
public GetDataSample(HttpServletRequest request, HttpServletResponse response, JspWriter out)
throws UnavailableException
{
// set up some stuff if you need to here
}
public GetDataSample()
{
//default contstructor
}
public ResultSet getRecordSet() throws UnavailableException
{
String url = "jdbcdbc:NorthWindJava";
Connection con;
ResultSet rs;
String createString;
createString = "Select FirstName, LastName, Title, Address from employees";
Statement stmt;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
con = DriverManager.getConnection(url, "uid", "psw"
stmt = con.createStatement();
rs = stmt.executeQuery(createString);
stmt.close();
con.close();
return rs;
}
catch (Exception e)
{
throw new UnavailableException(e.getMessage());
}
}
}