<%@ page language = "java" import="java.util.*, java.sql.*, java.io.*" %> <%@ page errorPage="wgroupErrorPage.jsp" %> <%! Connection con = null; %> <%! Statement stmt = null; %> <%! String custName; %> <%! String driver; %> <%! String URI; %> <%! String database; %> <%! String sqlStmt; %> <%! String user; %> <%! String password; %> <%! ResultSet rs = null; %> <% custName = request.getParameter("name"); if (custName == null || custName.equals("")) { request.setAttribute("faultPage", request.getRequestURI()); throw new Exception("No name specified. Go back and resubmit"); } %> <%-- These variables used for DB2 for iSeries --%> <%-- driver = "com.ibm.as400.access.AS400JDBCDriver"; URI = "jdbc:as400://"; database = "S103D64G"; sqlStmt = "SELECT LSTNAM, CUSNUM, BALDUE " + "FROM QIWS.QCUSTCDT " + "WHERE LSTNAM LIKE \'%"+ custName + "%\'"+ "ORDER BY LSTNAM"; user = "YOUR_USERID"; password = "YOUR_PASSWORD"; --%> <%-- These variables used for DB2 for Windows --%> <% driver = "COM.ibm.db2.jdbc.app.DB2Driver"; URI = "jdbc:db2:"; database = "testdb"; sqlStmt = "SELECT LSTNAM, CUSNUM, BALDUE " + "FROM " + database + ".QCUSTCDT " + "WHERE LSTNAM LIKE \'%" + custName + "%\' " + "ORDER BY LSTNAM"; user = "shaler"; password = "porcelain"; %> <%-- getConnection to database --%> <%! public Connection getConnection() { if (con != null) {return con;} try { Class.forName(driver).newInstance(); con = DriverManager.getConnection ( URI + database, user, password); } catch( Exception e) { // Send message to Web server log System.out.println("Error retrieving connection: " + e); return null; } return con; } %> DB2 Data Retrieval via JSP

List QCUSTCDT Table

Database: <%= database%>

<% con = getConnection(); if (con == null) { out.print("Connection failed. Check Web server log for reason."); return; } try { stmt = con.createStatement(); %> <% out.println(sqlStmt); %>

<% rs = stmt.executeQuery(sqlStmt); %> <% while (rs.next()) { %> <% } // end while (rs.next()) %>
Last Name Cust# Balance
<%= rs.getString("LSTNAM")%> <%= rs.getString("CUSNUM")%> <%= rs.getString("BALDUE")%>
<% rs.close(); stmt.close(); } catch (SQLException e) { out.println("SQL error : " + e); } out.flush(); %>