Solved

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

Posted on 2002-04-09
9
168 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count7 challenge 12 69
computer science syllabus 3 52
pairs challenge 5 44
eclipse formatting 6 41
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now