• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we use Map for accessing data from database.

 
Rupa Katkar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,
I want to access database using map. My database is in Oracle 10g.
can we access.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NO, you can't access database using Map, you need JDBC.
And if you want to store database row data into the Map, then you have to do something like this:

Please note, I haven't initialize the object.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And this shouldn't be asked in Servlet section, its related to JDBC and MUST be asked in JDBC section.
 
Rupa Katkar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Rohankar wrote:And this shouldn't be asked in Servlet section, its related to JDBC and MUST be asked in JDBC section.


Pl. tell me, how should i transfer my query to JDBC section..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already done.
 
Rupa Katkar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Rohankar wrote:NO, you can't access database using Map, you need JDBC.
And if you want to store database row data into the Map, then you have to do something like this:

Please note, I haven't initialize the object.





Hi..
I am using map for retrieving database contents..
Now i am able to save my contents in map, but i am not getting how to get it back
for displaying purpose / for further processing

My code is like this

Now here after i want to retrieve the data which i saved in this map.
how should i do this?
please tell me...
 
Jonathon Stride
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sample code from my project ^

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rupa Katkar wrote:Now here after i want to retrieve the data which i saved in this map.

Where do you want to display this data, Don't make us guessing !

Still, I guess its JSP :
 
Rupa Katkar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jonathon Stride wrote:sample code from my project ^




Actually the database with which i am dealing is very large.
so i think to retrieve its contents Map is suitable..
& here in Jonathon's code i am able to access only BATCH_NO from table.
remaining fields i am unable to access..
How should i access to fields.
 
Rupa Katkar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Rohankar wrote:
Rupa Katkar wrote:Now here after i want to retrieve the data which i saved in this map.

Where do you want to display this data, Don't make us guessing !

Still, I guess its JSP :



Hi Sagar,

I want to retrieve the table contents first, then i am going to process on that data.
& after processing the results i have display on jsp page.
But first i should able to retrieve the whole data from my database. my table contains thousands of records.
Please you suggest me should i go for Map or should i use something else.

Finally after processing data i am going to display it on jsp page only.

thanks for your support.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, I correct your original code:

Rupa Katkar wrote:& here in Jonathon's code i am able to access only BATCH_NO from table.
remaining fields i am unable to access..
How should i access to fields.


To access both the key and value:


But first i should able to retrieve the whole data from my database. my table contains thousands of records.
Please you suggest me should i go for Map or should i use something else.

Its depends upon, what you want to do with the data. Map's are used to associate the bunch of data with the unique identifier.
 
Rupa Katkar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Rohankar wrote:First, I correct your original code:

Rupa Katkar wrote:& here in Jonathon's code i am able to access only BATCH_NO from table.
remaining fields i am unable to access..
How should i access to fields.


To access both the key and value:


But first i should able to retrieve the whole data from my database. my table contains thousands of records.
Please you suggest me should i go for Map or should i use something else.

Its depends upon, what you want to do with the data. Map's are used to associate the bunch of data with the unique identifier.


Sagar, your code is working in my project, thanks for that..
One thing i want to ask is



in this code, we are not using this "b" object anywhere, how should we use it..
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rupa Katkar wrote:
in this code, we are not using this "b" object anywhere, how should we use it..

I think you want to use "bean", that's why I kept that code as it is. But if your need is fulfilled without using the bean instance "b", then you can delete that line.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic