• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Database and Vectors  RSS feed

 
Emile Ghazzawi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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!
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • 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
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!