![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 8
Rep Power: 0
![]() |
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 2:15 PM. |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Mar 2005
Location: different places. constantly on the run.
Posts: 57
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2005
Posts: 8
Rep Power: 0
![]() |
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. ![]() |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Mar 2005
Location: different places. constantly on the run.
Posts: 57
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Apr 2005
Posts: 8
Rep Power: 0
![]() |
The downside to Java...well one of them anyway ^-^.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|