This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Problem with Database and Vectors

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I am connecting with a JDBC database and pulling my values into a ResultSet and then transferring them into Vectors. However, when i pull a value from a Vector using the get() method it returns the value enclosed in square brackets, i.e. [value]. I know it is supposed to return an object but when i try to type cast to an integer i get a whole host of nasty looking error messages! The program compiles ok, its just that when the program trys to run the type cast the errors appear in the console window.

Has anyone got any ideas what i'm doing wrong here. I can't help but think that the values shouldn't be enclosed in square brackets and these are what are causing the problem.

Any help would be much appreciated as this problem has really got me stumped!
 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot just blindly cast an object to whatever you want. What is the object really? If you don't know use the instanceof operator to find out.
 
Emile Ghazzawi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have tried the instanceof method and it simply returns that it as an object? Although in Microsoft Access the field is set up as an integer!? Any other ideas would be greatly appreciated! I am fairly new to this so i may have missed something very obvious!

Thanks,

Emile
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A better approach might be using Data Transfer Object pattern to store the data instead of just putting them into the Vector.

Nick
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use object.getClass().getName() to find out the exact class of an object.

It might also help to show us some of your code and the exact error message(s) you get.
 
Emile Ghazzawi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for you help everyone, i solved the problem in the end. Somehow i had stupidly put a vector inside another vector, thats why it wasn't working!

Cheers,

Emile
 
Your buns are mine! But you can have this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic