Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

SQL command doesn't display anthing ?????

what is wrong with the sql command it doesn't display anithing
although it access the first sql and goes write
i'm geting the month and year from an html page as a text
but i defined them in access database as numbers .
is this the problem and how to solve it ,
any suggestions

===============================================
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class Startdate1 extends HttpServlet {
  public void doPost(HttpServletRequest req, HttpServletResponse res)
                                     throws ServletException, IOException {
 
         Connection con = null;          
         boolean logged = false;
         res.setContentType("text/html");
         PrintWriter out=res.getWriter();
         out.println("<HTML>");
         out.println("<HEAD><TITLE>Employee PaySlip</TITLE></HEAD>");
         out.println("<BODY BGCOLOR=\"#FFFFF\">");
         out.println("<CENTER>");
         out.println("<BR><BR>");
       try {
       
            String strSQL,strSQL1, userid,password;
            ResultSet rs=null, rs1=null;
            Statement stmt;
            int i=0,allowence=0;
            String month;
            String year;
               
            Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
            con = DriverManager.getConnection("jdbc:odbc:db1");
            stmt = con.createStatement();
               
               userid = req.getParameter("userid");
            password = req.getParameter("password");
            month = req.getParameter(month);
               year = req.getParameter(year);
               
               strSQL = "select * from LoginTable " +
               "where EmpID like '" + userid + "' and " +
               "Password like '" + password + "'";
            rs = stmt.executeQuery(strSQL);
               
           
                if (rs.next())                                                      
             {
                     logged=true;
                     out.println("LOGGED");
                     rs.close();
                }
                else
                {
                     logged =false;
                     out.println("not logged");
                     rs.close();
                }
                if (logged)
                {      
                     out.println("LOGGED2");
                strSQL1="SELECT AMOUNT FROM ALLDED WHERE EFFECTIVEDATE LIKE '"+month+"/"+"%"+"/"+year+"'"+"AND EMPNO ="+userid+"AND FLAG = 'A'";
             rs1 = stmt.executeQuery(strSQL1);
             out.println("LOGGED3");
               while(rs1.next())
               {
                    out.println("<TR>");                                                              
            out.println("<TD>" + rs.getString("AMOUNT") + "</TD>");
                out.println("</TR>");
                out.println("LOGGED4");
                }
                }
                else
                {
                    out.println("Please Check your id and password");
                }    
                  rs1.close();
               stmt.close();

       } catch (Exception e)
         {
           e.printStackTrace();
       }
         finally
         {
            if (con != null)
               {
                 try
                     {
                      con.close();
                 } catch (SQLException se) {
                      se.printStackTrace(System.err);
                 }
            }
       }
       out.println("</CENTER>");                                                
       out.println("</BODY>");                                                  
       out.println("</HTML>");  
  }    

}
0
star5
Asked:
star5
1 Solution
 
lazeknightCommented:
strSQL1="SELECT AMOUNT FROM ALLDED WHERE EFFECTIVEDATE LIKE '"+month+"/"+"%"+"/"+year+"'"+"AND
EMPNO ="+userid+"AND FLAG = 'A'";

--------------------------------------------------
Your EFFECTIVEDATE in Access has to be of type Date and your input should be something like = "'"+month+"/"+day+"/"+year"'"

0
 
objectsCommented:
I'm not sure if the database will support that type of query.  Have you tried executing the query directly, ie not from Java?
0
 
star5Author Commented:
the first part worked well

strSQL1="SELECT AMOUNT FROM ALLDED WHERE EFFECTIVEDATE LIKE '"+month+"/"+"%"+"/"+year+"'"

but when adding the second part doesn't work!!

strSQL1="SELECT AMOUNT FROM ALLDED WHERE EFFECTIVEDATE LIKE '"+month+"/"+"%"+"/"+year+"'"+"AND
EMPNO ="+userid+"AND FLAG = 'A'";


i tried in oracle and it work :
i wrote like that :

SELECT AMOUNT FROM ALLDED WHERE EFFECTIVEDATE LIKE '9/1/2001' AND
EMPNO =1000 AND FLAG = 'A';

whats the problem in java ??

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
objectsCommented:
What you tried in Oracle is not the same as what you tried in Java, it does not use any wildcarding. Did you try with the wildcard in Oracle?
0
 
star5Author Commented:
i found the solution :
do like that :

strSQL1="select amount,grade from allded where EMPNO like '"+userid+"'"+" AND FLAG like 'A'"+" and effectivedate like '"+mont+"/"+"%"+"/"+yea+"'";
0
 
pellepCommented:
I seem to recall that you have to put the 'LIKE' clauses at the end.

strSQL1="SELECT AMOUNT FROM ALLDED WHERE EMPNO ="+userid+" AND FLAG = 'A' AND EFFECTIVEDATE LIKE '"+month+"/"+"%"+"/"+year+"'";
0
 
sonthoshCommented:
Hope this answers ur query ..


strSQL1="SELECT AMOUNT FROM ALLDED
WHERE
EFFECTIVEDATE LIKE '"+month+"/"+"%"+"/"+year+"'"+" AND EMPNO ="+userid+"AND FLAG = 'A'";

I have tried it oracle. I am not wrong try print the query console u may find some problem in the query like  query framed in java using string might not be correct.




0
 
objectsCommented:
i thought he'd already found a solution.
0
 
MoondancerCommented:
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20284495.html
http://www.experts-exchange.com/questions/Q.20284978.html
http://www.experts-exchange.com/questions/Q.20286874.html
http://www.experts-exchange.com/questions/Q.20288082.html
http://www.experts-exchange.com/questions/Q.20287488.html
http://www.experts-exchange.com/questions/Q.20288869.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20285624.html
http://www.experts-exchange.com/questions/Q.20286675.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now