• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hash Tables and SQL  RSS feed

 
Prissy Marie
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I'm a very new beginner and I'm trying REALLY hard to just 'get' it... but I'm not sure if I'm struggling because of the tutors lack of information, or his wording just doesn't make sense... or if it isn't for me. (maybe even a joint effort!) I really want to get it, but I fear I keep over thinking things. I also apologise if this is in the wrong place.

So, I've created a SQL database for a previous assignment - all good.

Now, for this next one we have to create a hash table

Create a Hashtable using the Java Hashtable class.  - basically, they've given us a hash table code and we have to put that in our older assignment
Add the data for the SQL database to the Hashtable. - first name, last name, address and phone number
Then retrieve the data from the Hashtable to add it to the SQL statements.

I know what I have to do, but I can't work out how. How do I create a hash table that is supposed to have first name, last etc... etc?

This is what they gave us..




I have googled until I can no more. I've gone over reference notes; which there aren't any - at all. Nothing about connecting the two. He did say if we needed to, we can get help else where.  He recommended another forum, but they terrify me

Thanks if you read this far! Sorry I'm stupid
 
Carey Brown
Saloon Keeper
Posts: 2537
33
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would seem that you'd need to create a Contact class with first name, last name, address, and phone, and then have a HashMap<String,Contact>. Unless you need concurrency, use a HashMap instead. It's less clear what sort of key would be appropriate.
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We might create a GUID sort of thing to use as key.
 
Tony Docherty
Bartender
Posts: 3205
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or if it isn't for me.

Possibly, but probably not. Learning to program takes a huge amount of effort and every so often nothing makes sense and it feels like you will never be able to understand it. But if you keep trying you will get a sudden insight and it will all make sense (until you hit the next new concept).

Create a Hashtable using the Java Hashtable class.  - basically, they've given us a hash table code and we have to put that in our older assignment

Is the code you have shown something you have written, something you were given as an example of how to use a Hashtable or is it, as you say in your post, the Hashtable code you have to put that in your older assignment. I'm assuming it's the second of those options.

Add the data for the SQL database to the Hashtable. - first name, last name, address and phone number

Assuming you just have to store the data for a single record (if you need to store data for more than one record you need to use Carey's approach but I suspect that's beyond your knowledge at the moment) then you simply add each piece of data to the Hashtable using a key that describes what the data represents ie


Then retrieve the data from the Hashtable to add it to the SQL statements.

You can retrieve each piece of data by calling the Hashtables get() method passing in the key ie.
 
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!