problem with if else!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jesmi
    New Member
    • Apr 2007
    • 53

    #1

    problem with if else!!

    hi all

    i have a problem with my code.following is my code:



    [Codes]

    Connection con = null;
    PreparedStateme nt stmt = null;
    ResultSet rs = null;
    Map resultMap = null;
    List result = null;
    String sql="";


    try{
    con = Utilities.getDb Connection();

    sql="select * from tran_event where tran_event_cd is not null";

    if (chk1.equals("Y ") && !eventCd.equals ("null")){

    sql=sql + " AND event_cd='"+eve ntCd+"'";
    System.out.prin tln("anything.. .eventcode..... ....."+sql);
    }
    /* else
    {
    sql=sql;
    }*/


    if
    (chk2.equals("Y ") && !partyCd.equals ("null")){
    sql=sql + " AND party_cd='"+par tyCd+"'";
    System.out.prin tln("anything.. .partyCode..... ....."+sql);
    }
    /*else
    {
    sql=sql;
    }*/

    if
    (chk3.equals("Y ") && projectCd!="nul l"){
    sql=sql + " AND project_cd='"+p rojectCd+"'";
    System.out.prin tln("anything.. .projectcode... ......."+sql);
    }
    /* else
    {
    sql=sql;
    }*/
    if
    (chk4.equals("Y ") && fromDt!="null" && toDt!="null"){
    sql=sql + " AND event_dt between '"+fromDt+"' and '"+toDt+"'";

    }
    /* else
    {
    sql=sql;
    }*/
    stmt = con.prepareStat ement(sql);
    System.out.prin tln("check"+ stmt);


    rs = stmt.executeQue ry();
    [/Codes]

    my problem is that i need my sql statement to enter in each of the specified if condition. if the condition doesn't meet the requirement then the sql statement should be added to the next condition that meets the requirement.
    but my code only meets to that condition where the sql statement is placed just with that condition.

    so please help me

    thanks in advance
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by jesmi
    [code=java]
    if (chk1.equals("Y ") && !eventCd.equals ("null")){
    if (chk3.equals("Y ") && projectCd!="nul l"){
    [/code]
    I took two sample lines from your method; the first line correctly checks two
    strings for equality; the second line doesn't. Can you see the difference? There
    are more incorrect lines like that.

    btw, I notices you tried to tag your source code. The tag name is 'code', not 'codes'.

    kind regards,

    Jos

    Comment

    Working...