[thelist] Need help building a simple JSP/MySQL webapp

Rick den Haan rick.denhaan at gmail.com
Mon Jan 30 19:38:39 CST 2006

Hey guys,

I've been googling around a bit, but easy-to-understand JSP explanations
aren't easy to find. Let me start by saying that I'm a PHP programmer, and
this is my first time ever working with JSP, but I want to broaden my
horizons a bit and thought I'd start with something simple. Here's what I

My MySQL database is called "jsp_test", in which there's a table called
"customers" which has four columns for "id", "name", "address" and "phone".
I want a JSP page that ends up listing my customers, ordered by id. I.e.:

1. John Doe - 13, Java Drive - 555-1320
2. Jane Doe - 11, JSP Avenue - 555-5428

Normally, in PHP, I'd use a customers.php file that looks like this and does
the job:

  echo '<ol>';

  $sql = mysql_query("SELECT * FROM customers ORDER BY id ASC");
  while ($customers = mysql_fetch_array($sql)) {
    echo '<li>' . $customers["name"] . ' - ' . $customers["address"] . ' - '
. $customers["phone"] . '</li>';

  echo '</ol>';

For JSP, I have absolutely no clue where to go from what I have now. I have
an excellent Java guidebook (Y. Daniel Liang's "Introduction to Java
Programming", 5th Edition), which told me to go and download a MySQL JDBC
connector, which I did, but I don't know where to place it so that Tomcat
will be able to connect to it, nor what JSP code I have to use to connect to
it once I get it there.

Here's what I have right now (customers.jsp, adapted from an example in the
  //somehow load "com.mysql.jdbc.Driver"

  Connection jspdb = DriverManager.getConnection
  Statement sql = jspdb.createStatement();


  ResultSet customers = sql.executeQuery("SELECT * FROM customers ORDER BY
id ASC");

  while (customers.next()) {
    out.println("<li>" + customers.getString(1) + ' - ' +
customers.getString(2) + ' - ' + customers.getString(3) + '</li>');



Is someone more used to handling JSP can help me out here, please do.... Be
gentle, as this is my first time working with this language. I might be
thinking too much along PHP's mindset here...

Thanks in advance,

More information about the thelist mailing list