JSP Hosting
web hosting sales
(716) 689-1593

HostingServicesSupportOrderAbout UsSoftwareHome


Even experts read the manuals. Our tech support staff has most of the books that are out on a wide variety of web topics. Here are some of their top picks. We think you'll find them useful and informative as well.



JSP-JDBC Example

Database connections are an important part of presenting dynamic content. The following code snippet shows a simplified JSP page which connects to a database and displays the results of a query in a dynamically-generated HTML table.

 

 

<%@page language="java" import="java.sql.*"%>

<% Driver DriverRecordset1 =

(Driver)Class.forName("org.gjt.mm.mysql.Driver").newInstance();

Connection Conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/database",

    "username","password");

Statement StatementRecordset1 = Conn.createStatement();

ResultSet Recordset1 = StatementRecordset1.executeQuery("select * from mytable");

boolean Recordset1_isEmpty = !Recordset1.next();

boolean Recordset1_hasData = !Recordset1_isEmpty;

int Recordset1_numRows = 0;

%>

<%

int Repeat1__numRows = 10 ;

int Repeat1__index = 0 ;

Recordset1_numRows += Repeat1__numRows;

%>

<table>

<% while ((Recordset1_hasData)&&(Repeat1__numRows-- != 0))

{

%>

        <tr>

          <td><%= (String) Recordset1.getObject("Field1Name") %></td>

          <td><%= (String) Recordset1.getObject("Field2Name") %></td>

          <td><%= (String) Recordset1.getObject("Field3Name") %></td>

          <td><%= (String) Recordset1.getObject("Field4Name") %></td>

        </tr>

        <%Repeat1__index++;

Recordset1_hasData = Recordset1.next();}

%>

</table>

      <%

Recordset1.close();

Conn.close();

%>

JSP Examples

Note: MMA technical support staff cannot provide troubleshooting of problems with third-party CGI scripts including but not limited to: Perl scripts, C/C++ binaries, PHP or web/database integration unless these services are specifically contracted. For these services, please see our Quote Request Form.



Copyright © 1995-2012
Motivational Marketing Associates, LLC
All Rights Reserved.