View Full Version : JSP - Need example connecting to AS/400
Guest.Visitor
01-01-1995, 02:00 AM
I've searched in all the wrong places and cannot find an example of Java Server pages (JSP) that connect to a database on the AS/400. Don Denacourt had some good examples at COMMON but I didn't get a handout with the sample code. I'm not sure if the syntax is the same as straight Java to AS/400. Any code snippets would be greatly appreciated, Jim Quinlan Clearwater, Florida
Guest.Visitor
11-01-2000, 06:11 AM
I wrote a small JSP to list the project table in the sample data base provided with DB2 for Win95/98 to test the connection and logic. The working version is somewhat more complicated with includes and error catch logic. I hope this helps you somewhat. Regards, Tom Birchmire project.jsp <%-- Test JDBC connection using DB2 to link to sample data base --%> <%-- Load the JDBC driver class --%> <% Class.forName("COM.ibm.db2.jdbc.app.DB2Driver"); %> <%-- Get a connection --%> <% java.sql.Connection db = java.sql.DriverManager.getConnection ( "jdbc:db2:sample", "dbuser","dbuser"); %> <%-- Get a statement --%> <% java.sql.Statement st = db.createStatement(); %> <%-- Prepare a result set --%> <% java.sql.ResultSet rs; %> <H1> Project Listing </H1> <UL> <%-- Do the search --%> <% rs = st.executeQuery("SELECT projno,projname, deptno,respemp from project; "); %> <%-- go through the results --%> <% while (rs.next()) { %> <% String pno = rs.getString("projno"); %> <% String pname = rs.getString("projname"); %> <% String pdept = rs.getString("deptno"); %> <% String pemp = rs.getString("respemp"); %> <LI> <%=pno%> |<%=pname%> |<%=pdept%> | <%= pemp %> </LI> <% } %> [/list] <%-- Clean up after ourselves --%> <% rs.close(); %> <% st.close(); %> <% db.close(); %>
Guest.Visitor
11-01-2000, 07:08 AM
A million Thanks Tom. This will provide a good basis for experimenting. Jim Quinlan Clearwater, FL
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.