Esempio n. 1
0
  /**
   * displaying rows from element table
   */
  void displayElements ()
  {
    string sqlStmt = 
           "SELECT element_name, molar_volume, atomic_weight FROM elements \
    order by element_name";
    stmt = conn->createStatement (sqlStmt);
    ResultSet *rset = stmt->executeQuery ();
    try{
    cout.precision(7);
    while (rset->next ())
    {
      string elem_name = rset->getString(1);
      BFloat mol_vol = rset->getBFloat(2);
      BDouble at_wt = rset->getBDouble(3);

      cout << "Element Name: " << elem_name << endl;

      if ( mol_vol.isNull )
        cout << "Molar Volume is NULL" << endl;
      else
        cout << "Molar Volume: " << mol_vol.value << " cm3 mol-1" << endl;

      if ( at_wt.isNull )
        cout << "Atomic Weight is NULL" << endl;
      else
        cout << "Atomic Weight: " << at_wt.value << " g/mole" << endl;
    }
    }catch(SQLException ex)
    {
     cout<<"Exception thrown for displayElements"<<endl;
     cout<<"Error number: "<<  ex.getErrorCode() << endl;
     cout<<ex.getMessage() << endl;
    }

    stmt->closeResultSet (rset);
    conn->terminateStatement (stmt);
  }