• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

quaick question

 
joe weakers
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. I am connecting to an Oracle database using Oracle JDBC drivers and all that kind of thing. I then send sql select statements to retrieve the necessary information. Everything is fine to this point. The results of my query are then loaded into an OraceResultSet which contains two columns (my select statement requests string and float values from the one table). My dilemma is as follows. When parsing the result set is there a way of accessing the values stored in the two columns of the resultset based on their type. In my database table I have two columns: feature_name of type varchar2 and feature_weight of type float. Therefore the result set is a mirror image of this table. My code looks as follows:

OracleResultSet ors = (OracleResultSet) stmt.executeQuery(query);

while (ors.next()){
for(int i = 1; i <= 2; i++){
Object dbObject = ors.getObject(1);
weights.addElement(dbObject);
}
}

This code adds all the feature_names to a "weights" vector, i.e. ors.getObject(1). What I would like to do is set the weight of each feature_name to be its corresponding feature_weight in the database table using code like as follows:

public void setFeatureWeight(float weight){
this.weight = weight;
}

This is where my problem arises. How do I call my setFeatureWeight method when the elements of the second column in the OracleResultSet are not of type float. has anyone any suggestions? thank you Joe
 
Joe Ess
Bartender
Posts: 9320
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.sql.ResutSet , which I presume OracleResultSet extends, has a slew of type-specific methods. For instance, you could get your second column's value with getFloat() and invoke floatValue() to get the primitive value.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to move this to the JDBC forum. So please continue the discussion there. Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic