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 :(
LVL 2
clonmelogAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bloodredsunCommented:
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?
0
clonmelogAuthor Commented:
Yes, that was the firts thing that i checked!
0
fargoCommented:
this could be the same issue we were facing in the last question u posted.

check
1) String user = request.getParameter("employee"); what is the value getting from user?
2) for cross checking u can also do the following

ResultSet rs = ...

rs.last();
System.out.println("rs size is "+rs.getRow());
rs.beforeFirst();

while(rs.next()){...

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

bloodredsunCommented:
Also, check the column names are correct and don't have any capitalization. e.g. employee not Employee

You could try using getString(int column) rather than by name
0
KuldeepchaturvediCommented:
>> completely different thing than whats being discussed here...
one more thing that I noticed in your code is that you are using file:///C|/Documents%20and%20Settings for your images and pages..

while it will work on a local work station it will not work on a web setting...
As far as your database problem goes..
check if your form parameter is bringing any extra spaces at the start or end of the string...
also make sure that rs.getString(fieldname) is having correct field names ( including cases.... i.e. Emp_Name & not emp_name)..
0
a122178Commented:
1) View the source code from the browser that make sure whether it is a display issue.
2) I believe the problem is in the SELECT statement. Put database name before Employees == > DB.Employees . And see whether it works.

Hope it helps :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.