File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can't use data from resultSet

 
jmd odhiambo
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a newbie, i want to retrieve data from a resultSet and compare it to another string then make decision to do something. SOMEONE COME TO MY RESCUE. The code is as below

try {"com.mysql.jdbc.Driver"

con =java.sql.DriverManager.getConnection("jdbc:mysql://localhost/bus_service", "root", "");
st = con.createStatement();

String query = "SELECT seat_no, seat_state FROM bus_booking WHERE _to LIKE 'dd' AND date_of_travel LIKE 'ff' AND departing_time LIKE 'dd'" +
"ORDER BY seat_no ";
rs = st.executeQuery(query);
while (rs.next()) {
String s = rs.getString("seat_no");
String n = rs.getString("seat_state");
if(s == mike )// THIS IF STATEMENT STOPS MY CODE FROM FUNCTIONING
{
A1Button.setText(n);
}
}

st.close();
con.close();
} catch(java.sql.SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
 
Paul Clapham
Sheriff
Pie
Posts: 20187
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yeah. That's one of the standard beginner mistakes, nothing to do with JDBC. If you use "==" to compare two objects, that compares to see if they are the same object. But it's possible for two different String objects to contain the same data, and that's what you want to compare, isn't it? You want to compare the contents of the two String objects. For that you use the equals() method, like this:
<blockquote>code:
<pre name="code" class="core">if (s.equals(mike)) ...</pre>
</blockquote>
 
jmd odhiambo
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul it did work, cant believe it was that simple ha! at ma self....
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"javachizi odhiambo",
Please check your private messages.
-Ben
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic