Link to home
Start Free TrialLog in
Avatar of clonmelog
clonmelog

asked on

Query returning null data

Hi,

I have a form which is performing a user search by employee name (emp_name) from a form. the page is returning without an error with no results even when i hard code in the employee name to the query.

the code is:

<%@ page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<br>
<br><head>
<title>Momentum Marketing Intranet</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/text.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {font-size: 14px}
.style2 {
      font-family: "Times New Roman", Times, serif;
      font-size: 16px;
}
-->
</style></head>
<%

    Connection connection = null;
    try {
        // Load the JDBC driver
        String driverName = "oracle.jdbc.OracleDriver";
        Class.forName(driverName);
   
        // Create a connection to the database
        String serverName = "witnt07.wit.ie";
        String portNumber = "1521";
        String sid = "orawit";

        String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
        String username = "W01445693";
        String password = "EPDEXZ";
        connection = DriverManager.getConnection(url, username, password);
    } catch (ClassNotFoundException e) {
        out.println( "Could not find the database driver");
    } catch (SQLException e) {
      e.printStackTrace();
        out.println( "Could not connect to the database");
    }
      
%><body bgcolor="#FFFFFF">
<table width="770" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
  <tr>
    <td bgcolor="#FFFFFF">
      <table width="770" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td><a href="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/adminoptions.jsp"><img src="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/mom_logo.gif" width="256" height="74" border="0"></a></td>
          <td width="411">&nbsp;</td>
        </tr>
        <tr>
          <td width="359"><img src="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/leftbar.gif" width="359" height="39"></td>
          <td align="right" bgcolor="336CA1">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="2"><img src="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/topbar.gif" width="770" height="69"></td>
        </tr>
        <tr>
          <td colspan="2">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" background="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/but_bg.gif">
              <tr>
                <td align="right"><img src="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/spacer.gif" width="15" height="23"><img src="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/spacer.gif" width="15" height="23"><img src="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/spacer.gif" width="15" height="23"><img src="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/spacer.gif" width="15" height="23"><img src="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/spacer.gif" width="15" height="23"><img src="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/spacer.gif" width="45" height="23"></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <table width="770" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="167" rowspan="3" valign="top" bgcolor="8FBEE8">&nbsp; </td>
          <td colspan="2" align="center">
            <table width="95%" border="0" cellpadding="5" cellspacing="0" class="text">
              <tr>
                <td class="text">
                  <p><font color="#000000"><span class="style1"><br>
                    <%
                              String user = request.getParameter("employee");

       // Create a result set containing all data from my_table
        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM Employees where Emp_Name = '" + user + "'");

%>
<%while (rs.next ()){%>
                    </span></font><font color="#000000"><br>
                    </font></p>
                  <table width="100%" border="0">
                    <tr>
                      <td width="24%"><b>Employee ID:</b></td>
                      <td width="76%"><%=rs.getString("Emp_ID")%> </td>
                    </tr>
                    <tr>
                      <td width="24%"><b>Employee Name:</b></td>
                      <td width="76%"><%=rs.getString("Emp_Name")%></td>
                    </tr>
                    <tr>
                      <td width="24%"><b>Employee DOB:</b></td>
                      <td width="76%"><%= new java.text.SimpleDateFormat("dd/MMM/yy").format(rs.getDate("Emp_DOB"))%></td>
                    </tr>
                    <tr>
                      <td width="24%"><b>Employee Address:</b></td>
                      <td width="76%"><%=rs.getString("Emp_Address")%></td>
                    </tr>
                    <tr>
                      <td width="24%"><b>Employee Phone:</b></td>
                      <td width="76%"><%=rs.getString("Emp_Phone")%></td>
                    </tr>
                    <tr>
                      <td width="24%"><b>Employee Email:</b></td>
                      <td width="76%"><%=rs.getString("Emp_Email")%></td>
                    </tr>
                               <tr>
                      <td width="24%"><b>Employee Project:</b></td>
                      <td width="76%"><%=rs.getString("Emp_Project")%></td>
                    </tr>
                               <tr>
                      <td width="24%"><b>Employee Start:</b></td>
                      <td width="76%"><%= new java.text.SimpleDateFormat("dd/MMM/yy").format(rs.getDate("Emp_StartDate"))%></td>
                    </tr>
                               <tr>
                      <td width="24%"><b>Employee Bank No:</b></td>
                      <td width="76%"><%=rs.getString("Emp_BankDetails")%></td>
                    </tr>
                  </table>
                  <p><font color="#000000"><a href="file:///C|/Documents%20and%20Settings/01445693.AG05PC14/Desktop/momentum/adminoptions.jsp">Return to
                    Admin Options</a></font></p>
                  </td>
              </tr>
            </table>
                  <%}%>
                  <%
    connection.close();
%>
          </td>
        </tr>
        <tr>
          <td colspan="2" valign="bottom">
            <table width="82%" border="0" cellspacing="0" cellpadding="8">
              <tr>
                <td align="center" valign="bottom"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">&copy;
                  2005 Momentum Marketing Services Ltd.</font></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>

Im getting a connection to the db fine so im not sure why theres no data printed to the screen :(
Avatar of bloodredsun
bloodredsun
Flag of Australia image

My first query would be whether there is data in the database and whether the sql

SELECT * FROM Employees where Emp_Name = 'aUser'

returns any data. Can you check this?
Avatar of clonmelog
clonmelog

ASKER

Yes, that was the firts thing that i checked!
ASKER CERTIFIED SOLUTION
Avatar of fargo
fargo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial