Java: Converting textfield content to a String

Discussion in 'Programming' started by kathleenreyes, Dec 2, 2010.

  1. #1
    We wanted to get the text from the textfield to match it with our database and so we did this code but unfortunately we get a runtime error saying "FUNCTION srchTxfld.getText does not exist"

    
    
    String query1 = "SELECT * FROM clipdetails WHERE MATCH(clipTitle, clipAuthor, clipDate, clipNewspaper, clipSubject) AGAINST (srchTxfld.getText())";
    
    
    Code (markup):
    ...then we tried converting the content of textfield to a string but doesn't return any result.

    
    
    String x = srchTxfld.getText();
     
    String query1 = "SELECT * FROM clipdetails WHERE MATCH(clipTitle, clipAuthor, clipDate, clipNewspaper, clipSubject) AGAINST (x)";
    
    
    Code (markup):
    :confused:
    Hope you could help us... Thanks!
     
    kathleenreyes, Dec 2, 2010 IP
  2. Cozmic

    Cozmic Member

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #2
    Cozmic, Dec 2, 2010 IP
  3. kathleenreyes

    kathleenreyes Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    srchTxfld is the name for our JTextfield.
     
    kathleenreyes, Dec 2, 2010 IP
  4. Cozmic

    Cozmic Member

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #4
    Cozmic, Dec 2, 2010 IP
  5. kathleenreyes

    kathleenreyes Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes it is declared like this, JTextfield srchTxfld;

    Luckily, I found a solution.

    
    
    String query1 = "SELECT clipNo, clipTitle FROM clipdetails WHERE MATCH(clipTitle, clipAuthor, clipDate, clipNewspaper, clipSubject) AGAINST ('" + srchTxfld.getText() + "')";
    
    
    Code (markup):
    Anyway, Thanks Cozmic for replying. :D
     
    kathleenreyes, Dec 2, 2010 IP
  6. QiSoftware

    QiSoftware Well-Known Member

    Messages:
    805
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    158
    #6
    query statement looks wrong. "against"? should be something like-- "like" or <>.

    Q...
     
    QiSoftware, Dec 3, 2010 IP