aspose file tools*
The moose likes JDBC and the fly likes quaick question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "quaick question" Watch "quaick question" New topic
Author

quaick question

joe weakers
Ranch Hand

Joined: May 31, 2004
Posts: 38
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

Joined: Oct 29, 2001
Posts: 8866
    
    8

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

I'm going to move this to the JDBC forum. So please continue the discussion there. Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: quaick question