Results 1 to 13 of 13
  1. #1
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default Help with application

    Hi.

    Im a grade 12 student doing a PAT for my end of the year mark. I am trying to make a translator. Where I translate from one language to another.

    I have a database set up with two tables. "English" "Afrikaans" I have a field named ID in both tables which is numbered and there is a relationship between these two fields. Then a field named "English" in the one table and "Afrikaans" in the other.

    Now I want to know if anyone knows a SQL command that if a user enters a word into a text field that the program can search the database for that word, match the from the one table to the other table and give me the translated word?

    If you want screen shots of the database just ask and I will put it up.

    Hero

  2. #2
    cultclassic is offline Member
    Join Date
    Mar 2011
    Posts
    64
    Rep Power
    0

    Default

    You should post this in the database section.

    You have to use a SELECT statement.
    Something like:

    SELECT EnglishWord from EnglishTable where EnglishID=(SELECT AfrikaansID from AfrikaansTable where AfrikaansWord='Ubuntu');

    This is assuming that the words and translations have an 1 to 1 relationship.

  3. #3
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default

    Thanks. Will give it a try and will let you know if I get it right.

    Thanks

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Moved from Java Applets.

    If there's a one-to-one relationship, that looks like a bad database design. Why not have just one table with two columns, English and Afrikaans?

    db

  5. #5
    cultclassic is offline Member
    Join Date
    Mar 2011
    Posts
    64
    Rep Power
    0

    Default

    I'm assuming it is a school excercise.

  6. #6
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default

    Well. Its a school project.
    The teacher asked us to use to tables. So that we can learn relationships and all those wonderful things.

    Thanks cultclassic. The SQL works wonderful! Everything works now as it should :)

    Hero

  7. #7
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default

    Ok. I got one more question. Does anyone know how to make my GUI in Netbeans6.5 look like the windows look instead of the crappy java default metal/blue look? If possible can someone help me out?

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Add code to set the look and feel to be windows. Googling should get you lots of help.

  9. #9
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default

    I tried using google. But I need to change the .conf file and it doesnt allow me. Then I have to download some pluggin and and wat have you.

  10. #10
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default

    One other. When I do this to translate from English to Afrikaans SQL:
    public String option4 (String user)
    {
    StringBuffer sb = new StringBuffer ();
    try
    {
    boolean data = false;
    Statement stmt = conn.createStatement ();
    ResultSet b = stmt.executeQuery ("SELECT Afri FROM Afrikaans2 WHERE ID =(SELECT ID FROM English2 WHERE English like '" + user + "')");

    while (b.next ())
    {
    data = true;
    String afri = b.getString ("Afri");
    sb.append (afri);
    }
    //stmt.close();

    if (data == false)
    {
    new InformationUI ().setVisible (true);
    }
    }
    catch (Exception e)
    {
    System.out.println ("Error in option 3: " + e.toString ());
    }
    return sb.toString ();
    }
    It works fine. But for some odd reason when I use this one for the reverse translation:

    public String option3 (String word)
    {
    StringBuffer sb = new StringBuffer ();
    try
    {
    boolean data = false;
    Statement stmt = conn.createStatement ();
    ResultSet b = stmt.executeQuery (7401);

    while (b.next ())
    {
    data = true;
    String eng = b.getString ("English");
    sb.append (eng);
    }
    //stmt.close();

    if (data == false)
    {
    new InformasieUI ().setVisible (true);
    }
    }
    catch (Exception e)
    {
    System.out.println ("Error in option 3: " + e.toString ());
    }
    return sb.toString ();
    }
    It give me this error :

    Error in option 3: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] At most one record can be returned by this subquery.

    Error in option 3: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] At most one record can be returned by this subquery.

    Can anyone maybe see what the problem might be?

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    Can you please use code tags.
    Java Code:
    ResultSet b = stmt.executeQuery (7401);
    What on earth is this?
    This won't compile, so this can't be the code you ran.

    As a comment on your other method:
    Java Code:
    SELECT Afri FROM Afrikaans2 WHERE ID =(SELECT ID FROM English2 WHERE English like '" + user + "')
    This should be a join between Afrikaans2 and English2, then select where English like etc etc.
    Also it ought to be a PreparedStatement...what if the user String is:
    Java Code:
    "Something'in here"
    Then your SQL will fail.
    Never mind SQL injection.

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by Tolls View Post
    Never mind SQL injection.
    xkcd: Exploits of a Mom

    db

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    Exactly.
    Mrs Tolls wouldn't let me name any of our kids that...spoilsport.

Similar Threads

  1. Replies: 3
    Last Post: 12-04-2009, 12:10 PM
  2. Replies: 0
    Last Post: 04-22-2009, 01:30 PM
  3. Replies: 0
    Last Post: 02-16-2008, 09:31 PM
  4. Replies: 0
    Last Post: 02-16-2008, 09:29 PM
  5. how to use JTA for application
    By mary in forum Advanced Java
    Replies: 1
    Last Post: 07-13-2007, 04:34 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
  •