java


put data to hashmap without overwrite


i want add values to hashmap get from DB.resulset has 2 row data.but its overwrite firstly added row values.
this is my code.
Statement s1 = con.createStatement();
ResultSet rs1 = s1.executeQuery("SELECT * FROM garantee WHERE loanapplicationid ='" + applicationid + "'");
ResultSetMetaData garanteeMetaData = rs1.getMetaData();
int garanteeColumns = garanteeMetaData.getColumnCount();
HashMap<String, String> garanteeFull = new HashMap<String, String>();
while (rs1.next()) {
int j = 1;
for (int i = 1; i < garanteeColumns; i++) {
garanteeFull.put(garanteeMetaData.getColumnLabel(i) + j, rs1.getString(i));
System.out.println(rs1.getString(i));
}
j++;
}
i use int j to change key value.but its not work corectly.please help me.how to do that
**sorry for bad English
I think you should use the following line outside while loop as whenever it's coming to the loop the value of j is becoming 1 every time.
int j = 1;
So please try with following code replacing your one..
Statement s1 = con.createStatement();
ResultSet rs1 = s1.executeQuery("SELECT * FROM garantee WHERE loanapplicationid ='" + applicationid + "'");
ResultSetMetaData garanteeMetaData = rs1.getMetaData();
int garanteeColumns = garanteeMetaData.getColumnCount();
HashMap<String, String> garanteeFull = new HashMap<String, String>();
int j = 1;
while (rs1.next()) {
for (int i = 1; i < garanteeColumns; i++) {
garanteeFull.put(garanteeMetaData.getColumnLabel(i) + j, rs1.getString(i));
System.out.println(rs1.getString(i));
}
j++;
}

Related Links

com.mysql.jdbc.Driver Error when I run the Jar File although that exists in my Build Path
What is the best way to share only the getter methods to client?
postgresql driver not loaded by the OSGI container?
Eclipse E4 RCP global error handling
PayPal Integration with java
am getting error with android studio R.java
How do i remove \r\n in a JSON file
is there a difference between searching in txt files and searching in html file in java-android
SymmetricDS conditional sync
TreeMap get first element and remove
Count Distinct String Object Instances
Can't add java overlay via layman
onOptionsItemSelected is not working in android?
How to sum the digits of two integers?
Why does declaring similar object name with HashMap has no conflict?
One ReentrantReadWriteLock instance per Variable to be synchronized?

Categories

HOME
google-chrome-extension
variables
cloud
cookies
stock
fft
platform-builder
kalman-filter
elm
sharepoint-designer
ip
fsm
multiple-records
pheatmap
primary-key
maude-system
etl
google-cloud-spanner
moonmail
static-libraries
visual-studio-2005
highlight.js
sms-gateway
contextmenu
shared-hosting
immutable.js
devops
wijmo
su
bootstrap-duallistbox
intel-pin
user-interaction
info.plist
file-rename
librato
media-queries
pdb
avcapturesession
textmate
openoffice.org
android-kernel
code-search-engine
android-fingerprint-api
botbuilder
babel-core
upstart
togetherjs
typed-lambda-calculus
sqldf
chord-diagram
google-feed-api
ctest
player
websitepanel
react-native-listview
superstack
pyke
cloudbees
phpcas
qtableview
teamcity-8.0
t4mvc
python-3.2
sframe
tableau-online
mono-embedding
sortedlist
formatjs
tt-news
android-imagebutton
cctv
codeigniter-routing
preferences
android-radiobutton
wp-query
jboss-weld
meteor-velocity
multiprocessor
xsockets.net
aqtime
ftps
flash-builder4.5
cos
orchardcms-1.7
type-equivalence
distutils
onsubmit
cufon
eclipse-templates
web-application-design
routedevent
asp.net-profiles
firefox4
zend-tool
mtj
w3wp
windows-live-messenger

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App