Solved

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

Posted on 2002-04-09
9
173 Views
Last Modified: 2010-03-31
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
Comment
Question by:star5
9 Comments
 

Expert Comment

by:lazeknight
ID: 6929457
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
 
LVL 92

Expert Comment

by:objects
ID: 6929662
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
 

Author Comment

by:star5
ID: 6930460
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 6930476
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
 

Author Comment

by:star5
ID: 6930606
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
 
LVL 4

Expert Comment

by:pellep
ID: 6930847
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
 

Accepted Solution

by:
sonthosh earned 9 total points
ID: 6933073
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
 
LVL 92

Expert Comment

by:objects
ID: 6933083
i thought he'd already found a solution.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6956463
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question