Hi to everybody,
I have a servlet that connects to an Access DB and all it does it retrieves
two columns of data from a table and displays it in HTML. What I want to d
ois to use System.out.println()s in order to show on the console that
servlet is activated, the right is received etc.. How exactly do I use
System.out.println()s instead of using PrintWriter's out.println()s to show
anything that I want on the browser? Basically where do I put
theSystem.out.println()s in my code? Here is my simple example:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SimpleLoginServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try {
//Load the MS Access driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Get a connection to the database
con = DriverManager.getConnection("jdbc:odbc:RoomBookDB", "andreas",
"stellatos");
//Create a statement object
stmt = con.createStatement();
//Execute SQL query and get a result set
rs = stmt.executeQuery("SELECT USERNAME, PASSWORD FROM LECTURERS");
// Display the result set as a list
out.println("<HTML><HEAD><TITLE>Confidential List</TITLE><HEAD>");
out.println("<BODY>");
out.println("<UL>");
while(rs.next()) {
out.println("<LI>" + rs.getString("username") + " " +
rs.getString("password"));
}
out.println("</UL>");
out.println("</BODY></HTML>");
}
catch(ClassNotFoundException e) {
out.println("Couldn't load the database driver: " + e.getMessage());
}
catch(SQLException e) {
out.println("SQL Exception caught: " + e.getMessage());
}
finally {
//Always close the database connection
try {
if (con != null) con.close();
}
catch (SQLException ignored) { }
}
}
}
Thanks for the help,
Andreas
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html