Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 27th, 2005, 2:47 PM   #1
Vengeance
Newbie
 
Join Date: Apr 2005
Posts: 8
Rep Power: 0 Vengeance is on a distinguished road
Java - Searching a table in a database - small problem.

Ok, below is the code.

void searchBtn_actionPerformed(ActionEvent e) {

String searchfilmName = searchtxtbox.getText();

try {
store.setFileName( "FilmDatabase.jds" );
store.setUserName( "odeon" );
store.setPassword( "1234" );
table.setStoreName( "FILMTABLE" );
table.setStore( store );
table.open();

table.setSort( new SortDescriptor( new String[] {"FILMID"} ) );
table.first();
while ( table.inBounds() ) {

table.getInt( "FILMID" );
String filmName;
filmName = table.getString( "FILMNAME" ).toLowerCase();

if (filmName == searchfilmName) {
System.out.println( "Film found! Synopsis: " + table.getString( "SYNOPSIS" ) );
}

else {
System.out.println( "Film not found!" );
}

table.next();


/* System.out.println( table.getInt( "FILMID" ) + ": "
+ table.getString( "FILMNAME" ) + ", "
+ table.getString( "SYNOPSIS"));
table.next();*/
}
} catch ( DataSetException dse ) {
dse.printStackTrace();
} finally {
try {
store.close();
table.close();
} catch ( DataSetException dse ) {
dse.printStackTrace();
}
}

}
}

Now, as you can see there is a section of code in a comment. When I use this code, it prints off all the information of the database perfectly.
Prints the ID, name, and synopsis. But, for some reason when it's searching it doesn't recognise things.

For instance, earlier I made a small adjustment so it would print off the string entered and the string it was comparing it to.

Now, I type in "hitch" which is one of the films in the database it said "hitch, hitch" both look exactly the same right? No capitals..spaces, etc.

But, for some reason it doesn't see them as the same.

Can anyone help me with this? I'm so confused as to why it doesn't think they're the same thing.

Btw, I'm using Jbuilder and importing classes JDataStore and DataExpress.

I can extract data from the database fine...it's just it thinks the strings aren't the same even though they are.

Last edited by Vengeance; Apr 27th, 2005 at 3:15 PM.
Vengeance is offline   Reply With Quote
Old Apr 28th, 2005, 3:46 AM   #2
Easter Bunny
Programmer
 
Easter Bunny's Avatar
 
Join Date: Mar 2005
Location: different places. constantly on the run.
Posts: 57
Rep Power: 4 Easter Bunny is on a distinguished road
filmName.equals( searchfilmName )

can't compare strings with "==". use method equals or equalsIgnoreCase(). you'll find it in String's api.
__________________
There's got to be more to life than being really, really
ridiculously good looking
Easter Bunny is offline   Reply With Quote
Old Apr 28th, 2005, 4:43 AM   #3
Vengeance
Newbie
 
Join Date: Apr 2005
Posts: 8
Rep Power: 0 Vengeance is on a distinguished road
Dude, that worked! Omg thank you sooooo much. I promise I won't become a "one poster" ;p. I knew it had to be something like that...I was using the "match" method...lol im so dumb.

Thank you very very very much.

Vengeance is offline   Reply With Quote
Old Apr 28th, 2005, 6:40 AM   #4
Easter Bunny
Programmer
 
Easter Bunny's Avatar
 
Join Date: Mar 2005
Location: different places. constantly on the run.
Posts: 57
Rep Power: 4 Easter Bunny is on a distinguished road
should have heard the swearing when i tried to find stuff in a database. took me hours to find out that you need to use % when you wanna use "like".
__________________
There's got to be more to life than being really, really
ridiculously good looking
Easter Bunny is offline   Reply With Quote
Old Apr 28th, 2005, 3:53 PM   #5
Vengeance
Newbie
 
Join Date: Apr 2005
Posts: 8
Rep Power: 0 Vengeance is on a distinguished road
The downside to Java...well one of them anyway ^-^.
Vengeance is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC