Results 1 to 13 of 13
  1. #1
    Bulelakes is offline Member
    Join Date
    Jul 2010
    Posts
    32
    Rep Power
    0

    Default compare String to the character .

    Good morning Sir


    I have this problem below , here I need to compare the user code from the database with the user code from the textfield
    but I cannot because the one in the database is in char format and there is no resultSet method to get characters
    here is my code.


    while(rec.next())
    {
    x = useridText.getText();

    user = rec.getString("user_code");
    if (x.equalsIgnoreCase(user)) {
    System.out.println("user_code in");
    }
    else {
    System.out.println("user_code out");

    }
    }

    I tried the following but still didnít work :
    String u = ((String)user); // to cast the value to a string
    String usr= String.valueOf(user); // to get the character value and put it in String variable.

    I really need your assistance here.

    Thanks

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    If user is a String it does work, but keep in mind that the value AAA from a char(6) column in the DB will be 'AAA___' (trailing blanks), so you need to trim.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Does anyone still create tables with CHAR columns instead of VARCHAR?

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Probably :rolleyes:
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    Bulelakes is offline Member
    Join Date
    Jul 2010
    Posts
    32
    Rep Power
    0

    Default Thanks PhHein Trim works well

    here is my code below
    Now it does not want to stop runing when i click the Button,
    Suppose to display the details of the inner loop to the List and stop run
    but instead it does display but does not stop running.
    any suggestions

    while (rec.next()) {

    x = useridText.getText();
    user = rec.getString("user_code");
    usr = user.trim();
    if (x.equals(usr)) {

    plannames = "select table_name from all_tables where owner='PLANNER' and table_name like'AXZ%'order by table_name";

    statement = connect.connection.createStatement();
    ResultSet rs = statement.executeQuery(plannames);


    while (rs.next()) {

    String table_nam = rs.getString(1);
    model.addElement(table_nam);
    planlockarea1.add(table_nam);


    }

    }

    }

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    What do you mean by "does not stop running"?
    What is it you're seeing that you don't expect to see?

  7. #7
    Bulelakes is offline Member
    Join Date
    Jul 2010
    Posts
    32
    Rep Power
    0

    Default

    Its like it has endless loop ,keeps on running.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    What doesn't stop running though?
    Which bit?
    Is your app supposed to shutdown after displaying?
    Remember I cannot see what's happening on your machine.

  9. #9
    Bulelakes is offline Member
    Join Date
    Jul 2010
    Posts
    32
    Rep Power
    0

    Default

    Loops does not stop , its endless

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Which loop doesn't stop?

    Blimey, this is like getting blood from a stone...

  11. #11
    Bulelakes is offline Member
    Join Date
    Jul 2010
    Posts
    32
    Rep Power
    0

    Default

    Just have a look at this code ,I think it does that bcz it has while loop inside the other while loop.

    if(e.getSource()==queryBtn)
    {
    try {
    String user = "";
    userids = "SELECT user_code FROM usr_pln_rghts ";
    statement = connect.connection.createStatement();
    ResultSet rec = statement.executeQuery(userids);
    while (rec.next()) {

    x = useridText.getText();
    user = rec.getString("user_code");
    usr = user.trim();
    if (x.equals(usr)) {

    plannames = "select table_name from all_tables where owner='PLANNER' and table_name like'AXZ%'order by table_name";

    statement = connect.connection.createStatement();
    ResultSet rs = statement.executeQuery(plannames);


    while (rs.next()) {

    String table_nam = rs.getString(1);
    model.addElement(table_nam);
    planlockaList.add(table_nam);


    }

    }

    }

    }catch (SQLException ex) {
    Logger.getLogger(freeUserUI.class.getName()).log(L evel.SEVERE, null, ex);
    }

    }

    }

  12. #12
    Bulelakes is offline Member
    Join Date
    Jul 2010
    Posts
    32
    Rep Power
    0

    Default

    oh no i got it right the reason of it was that i was creating connect twice!! Thanks

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Just so you know, you're going to leak resources on the db.
    You're not closing any of your statements or result sets.

Similar Threads

  1. Replies: 8
    Last Post: 02-22-2014, 09:06 AM
  2. How compare two String?
    By artemff in forum New To Java
    Replies: 8
    Last Post: 08-29-2011, 09:00 AM
  3. compare sql resultset with a String
    By cotarelo in forum Networking
    Replies: 6
    Last Post: 06-21-2010, 04:53 PM
  4. String compare issues?
    By emp in forum New To Java
    Replies: 3
    Last Post: 04-21-2009, 08:16 AM
  5. String Compare not working
    By Revelation in forum New To Java
    Replies: 3
    Last Post: 06-30-2007, 07:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •