Store ResultSt Data in a Map

Ads
 

Store ResultSt Data in a Map

i want to store data in a hash Map .Please solve my problem as soon as possible.

View Answers

September 13, 2011 at 11:03 AM

import java.sql.*;
import java.util.*;

public class MapExample {
    public static void main(String[] args) {
    Map<String,String> map = new HashMap<String,String>();
      try{
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
      Statement st = con.createStatement();
      ResultSet rs = st.executeQuery("SELECT * FROM  data");
      while(rs.next()){
        map.put(rs.getString("id"),rs.getString("name"));
      }
       System.out.print(map);
      }
      catch(Exception e{
        System.out.print(e);
      }
    }

}

Ads









Related Tutorials/Questions & Answers:
Store ResultSt Data in a Map
Store ResultSt Data in a Map  i want to store data in a hash Map .Please solve my problem as soon as possible
How to hold data in map
How to hold data in map  Holding data in map: i have user1 and he has account1,account2,accoutn3 like that user2,user3 will have accounts. now how to hold users and their accounts in hashmap
Advertisements
read from file and store using hash map
read from file and store using hash map  I was stuck with a java project where I have to read a file with two different concepts and store them differently in hashmap. My data file would be something like Adults: Name, xyz
iPad App to store data
iPad App to store data  Hi, How to add data support iPad application? Thanks
store and retrieve data
store and retrieve data  sir,i want to store the entering data in a word file and retrieve it when i need.i am try to develop a video portal.in which... Write data into word file For this, poi-scratchpad-3.7-20101029.jar is needed
servlet program for data store in oracle?
servlet program for data store in oracle?  how to store data in oracle through servlet program
Java Xml Data Store
be followed up and/or purchased. You will need to store the data in a local binary... the implementation needs to change later on (perhaps they might decide to store the data...Java Xml Data Store  I have to do this project and i'm finding it so
store form data into word document
store form data into word document  i want form page data, ex username phone number.. to store it in a word document file
how to store,retrieve,modify the data
how to store,retrieve,modify the data  hello sir ,how to store,retrieve,modify the data using the swing please help me
to store data entered in html page
to store data entered in html page  i want to a job site... submit we have to move to form 2 on there we have enter text data in the textfield after that by clicking submit button data enter in form 1 and 2 should
store data from a variable in mysql?
store data from a variable in mysql?  sir last time asked you tell me how to retrieve data from a database mysql and store it in an int variable in order to apply some calculation on it, but now i want to store the result
ModuleNotFoundError: No module named 'wrattler-data-store'
ModuleNotFoundError: No module named 'wrattler-data-store'  Hi, My... named 'wrattler-data-store' How to remove the ModuleNotFoundError: No module named 'wrattler-data-store' error? Thanks   Hi
ModuleNotFoundError: No module named 'nifeng-data-store'
ModuleNotFoundError: No module named 'nifeng-data-store'  Hi, My... named 'nifeng-data-store' How to remove the ModuleNotFoundError: No module named 'nifeng-data-store' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'wrattler-data-store'
ModuleNotFoundError: No module named 'wrattler-data-store'  Hi, My... named 'wrattler-data-store' How to remove the ModuleNotFoundError: No module named 'wrattler-data-store' error? Thanks   Hi
project in JSP and XML(to store data)
project in JSP and XML(to store data)  I need to complete an assignment in JSP and using XML as Database ,Please help me to complete this assignment.Ill be very very thankful to you,i am new to JSP.Please provide full code
JSP and XML .data store nd retrieve
JSP and XML .data store nd retrieve  I have made a form in jsp having emp id, projectname and emp name.I want to store data related to employee in xml file.How can i store data entered by user in XML file and later retrieve data
Store data in HTML forms from Excel sheet
Store data in HTML forms from Excel sheet  I have a excel file having multiple coloums, and having one Html page having forms corrospoding to excel coloums. I want to auto fill up the excel data into html forms, Any one please
store
store  i want to store data in (.dat) file format using swing and perform operation on that insertion,deletion and update
retrieve data from mysql database and store it in a variable ?
retrieve data from mysql database and store it in a variable ?  sir , I am working on a project , in which I have to apply operation on input data... to store that data in int variable. how to do this ?   Here is an example
data type used to store name.(getting an error)
data type used to store name.(getting an error)    Statement stm=con.createStatement(); String query="select * from employee where ename=\'"+ename+"\'"; ResultSet rs=stm.executeQuery(query
how to get data from list to map with out using a loop?
how to get data from list to map with out using a loop?  List list...("15"); how to get this data into map with out using a loop. i want this data like this--map.put(name,id); Is it possible to do without using loop
map
map  using map, i want display message based on id selected [both are strings]   i do no   Hi Friend, Try the following code...) { Map map=new HashMap(); map.put("Message1","Hello
Map
Map  If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map either iterator or for each loop or for loop
how to store data in other table using servlet and jsp
how to store data in other table using servlet and jsp  pls can anyone tell how to store data in other table using servlet and jsp and want to display that data too.and the data in first table must be same.pls help
how to store JTree data hierarchically in mysql database from netbeans
how to store JTree data hierarchically in mysql database from netbeans  how to store JTree data hierarchically in mysql database from netbeans. I am new to this topics so I need a program and tables you are using in database
store
store  hi i want store some information in my program and use them in other method. what shoud i do
How to store data entered in JSP page by a user in XML file & later retrieval of data using id at other page
How to store data entered in JSP page by a user in XML file & later retrieval..., projectname and emp name.I want to store data related to employee in xml file.How can i store data entered by user in XML file and later retrieve data
How to passed the ID's in MAP how to stored whaterver select the name that only ID should store in db using SWING/AWT?
the ID's in MAP how to stored whaterver select the name that ID should store...How to passed the ID's in MAP how to stored whaterver select the name that only ID should store in db using SWING/AWT?  Hi, I am working on SWING
How to store data entered by User in JSP page in XML file
How to store data entered by User in JSP page in XML file  How to store data entered by user in JSP page to be saved in XML file.On clicking submit...   JSP store data entered by user into XML file 1)form.jsp: <html>
Stoting file name in Map
Stoting file name in Map  how to store id and file name in map
Google Map Integration - Ajax
Google Map Integration  Hi All, I am working on a vehicle tracking system project. I have to read data from sql server database and map the vehicle position in google map. I need to use ajax as the data is updated in every

Ads