Results 1 to 13 of 13
Thread: Help with application
- 05-24-2011, 05:33 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
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
- 05-24-2011, 06:04 PM #2
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
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.
- 05-24-2011, 08:50 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
Thanks. Will give it a try and will let you know if I get it right.
Thanks
- 05-24-2011, 09:04 PM #4
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
- 05-24-2011, 09:35 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
I'm assuming it is a school excercise.
- 05-24-2011, 09:42 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
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
- 06-01-2011, 07:29 PM #7
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
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?
- 06-01-2011, 07:47 PM #8
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Add code to set the look and feel to be windows. Googling should get you lots of help.
- 06-02-2011, 06:38 PM #9
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
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.
- 06-02-2011, 08:50 PM #10
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
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?
- 06-03-2011, 09:45 AM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Can you please use code tags.
What on earth is this?Java Code:ResultSet b = stmt.executeQuery (7401);
This won't compile, so this can't be the code you ran.
As a comment on your other method:
This should be a join between Afrikaans2 and English2, then select where English like etc etc.Java Code:SELECT Afri FROM Afrikaans2 WHERE ID =(SELECT ID FROM English2 WHERE English like '" + user + "')
Also it ought to be a PreparedStatement...what if the user String is:
Then your SQL will fail.Java Code:"Something'in here"
Never mind SQL injection.
- 06-03-2011, 11:24 AM #12
- 06-03-2011, 11:26 AM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Help in converting Java application to desktop application in Netbeans
By realahmed8 in forum AWT / SwingReplies: 3Last Post: 12-04-2009, 12:10 PM -
Sending J2ME application by blue tooth (by J2ME application). Very URGENT!!!
By maruffaiz in forum CLDC and MIDPReplies: 0Last Post: 04-22-2009, 01:30 PM -
Launching an application from another application dynamically
By Java Tip in forum Java TipReplies: 0Last Post: 02-16-2008, 09:31 PM -
Launching an application from another application using thread
By Java Tip in forum Java TipReplies: 0Last Post: 02-16-2008, 09:29 PM -
how to use JTA for application
By mary in forum Advanced JavaReplies: 1Last Post: 07-13-2007, 04:34 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks