aspose file tools*
The moose likes JDBC and the fly likes Can we use Map for accessing data from database. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Can we use Map for accessing data from database. " Watch "Can we use Map for accessing data from database. " New topic
Author

Can we use Map for accessing data from database.

Rupa Katkar
Ranch Hand

Joined: Aug 12, 2009
Posts: 35
Hi to all,
I want to access database using map. My database is in Oracle 10g.
can we access.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

And this shouldn't be asked in Servlet section, its related to JDBC and MUST be asked in JDBC section.
Rupa Katkar
Ranch Hand

Joined: Aug 12, 2009
Posts: 35
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

Joined: Jan 10, 2002
Posts: 61594
    
  67

Already done.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rupa Katkar
Ranch Hand

Joined: Aug 12, 2009
Posts: 35
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

Joined: Aug 06, 2009
Posts: 34
sample code from my project ^



2 interviews failed cause of not having SCJP ( and counting...)
not anymore !

SCJP 6 (70%)

now ready to count other reasons :P...
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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

Joined: Aug 12, 2009
Posts: 35
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

Joined: Aug 12, 2009
Posts: 35
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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

Joined: Aug 12, 2009
Posts: 35
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we use Map for accessing data from database.