Helpful Information
 
 
Category: DB2 Development
JSP with DB2

Hi, i cant seem to get DB2 data to display on my JSP page. Is it because of my coding or because for the db2driver? Attached below is a copy of my class file.


package WH;

import java.sql.*;
import java.sql.Statement;

public class DbConnect1 {

private String dbUser = "XXX";
private String dbPasswd = "XXX";
private String dbDriver = "COM.ibm.db2.jdbc.app.DB2Driver";
private String dbURL = "jdbc:db2:http://XXXX:8080/invsys";

private Connection dbCon;

public DbConnect1(){}

public boolean connect() throws ClassNotFoundException,SQLException{
try
{
Class.forName(dbDriver);
System.out.println("Loaded the instantDB JDBC driver.");
dbCon = DriverManager.getConnection(dbURL, dbUser, dbPasswd);
System.out.println("Created and connected to database TimingTest");
return true;
}

catch (Throwable e)
{
e.printStackTrace();
System.out.println("FAIL LAHHHHHHHHHHHH");
return false;
}
}

public void close() throws SQLException{
dbCon.close();
}

//accepts the SQL query in the form of a string from the JSP file in which this bean is implemented
public ResultSet execSQL(String sql) throws SQLException{
System.out.println("haha");



//initiates the connection with the dbCon connection object
Statement s = dbCon.createStatement();
ResultSet r = s.executeQuery(sql);
return (r == null) ? null : r;
}

public int updateSQL(String sql) throws SQLException{
Statement s = dbCon.createStatement();
int r = s.executeUpdate(sql);
return (r == 0) ? 0 : r;
}
}

Here is my JSP file.

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

<jsp:useBean id="DbConnectBean1" scope="page" class="WH.DbConnect1" />
<%
//Get status
/*String message;
String status = request.getParameter("status").trim();

if (status == "duplicateEmail")
message="Please try again. An account with the same emaill address has already been created.";
else if (status == "deleteOk")
message="Delete successful.";
else
message="";*/

//Get Contacts
String name;
String email;
String extNo;
String phoneNo;
String remarks;
String SQLstmt;

SQLstmt = "Select * from CONTACT";
if (DbConnectBean1.connect()==true){

%>
<html>
<head>
<title>Display Contacts</title>
<script src="validation.js" language="Javascript"></script>
<script Language="JavaScript">
//Perform Validation
/* function checkForm() {
var alertString=checkChkBox(theForm.chkItem.value);
formSubmit(alertString);
}*/
</script>
</head>
<body bgcolor="#ffffff">
<form action="USRDelContact.jsp" name="theForm" onsubmit="return checkForm();">
</form>
<table>
<tr>
<td><input type="chkAll" id="chkAll"onclick="checkAll(document.theForm.chkItem)"/></td>
<td>Name</td>
<td>Extension No.</td>
<td>Mobile Phone No.</td>
<td>Email Address</td>
<td>Remarks</td>
<td>&nbsp;</td>
</tr>
<%

ResultSet r = DbConnectBean1.execSQL(SQLstmt);
while (r.next()){
%>
<tr>
<td><input type="checkbox" name="chkItem" id="chkItem" value="<%= r.getString("Email")%>"/></td>
<td><%= r.getString("Emp_Name")%></td>
<td><%= r.getString("Ext_No")%></td>
<td><%= r.getString("Cellphone")%></td>
<td><a href="mailto:<%= r.getString("Email")%>"><%= r.getString("Email")%></a></td>
<td><%= r.getString("Remarks")%></td>
<td><a href="USREditContact.jsp?email=<%= r.getString("Email")%>">Edit</a></td>
</tr>
<%
}

if (r.next()==false)
{
%>
<tr>
<td colspan="7">There are no records currently.</td>
</tr>
<% }
}//end if%>
<tr colspan="6">
<td>
<%//=message%> <input type="submit" name="btnDelete" value="Delete">
</td>
</tr>
</table>
</form>
</body>
</html>

You'll get a better response if you post something more descriptive about what you can't do.

- Is the code compiling? If not, what's the error message?
- Is there a runtime exception? If so, what's the error message?
- Is your page not displaying information? What should it be doing, and what's happening instead?

Also, it's best to try and filter your code down to the essential elements that you're having problems with. The amount that you've posted isn't going to be scanned through by a lot of people.










privacy (GDPR)