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

Android jni UnsatisfiedLinkError wrong function name
Selendroid: By locator ByCssSelector is curently not supported
Why can't I try-with-resources in MY servlet?
Can you use JDBC to connect to just an instance without specifying a database?
Why is my redirectAttributes.addFlashAttribute and data Re-populating not working after validation fails?
Java 8 Lambdas - Bitwise AND Operations
how to format string line that contains numbers with regex
Java code to create bigquery table using json schema
Java androd ExpandableListView checkbox in group view
Counting the number of times a specific word appears in a txt file while using a try/catch block in java
Target lines Javadoc
How to format MonetaryAmount with currency symbol?
what is use for switching to next column in programs
Numeric cell values in excel are read abnormally with extra digits appended after decimal point
Translating java code to python, IDE suggestions?
how to exclude fridays on my countdown [duplicate]

Categories

HOME
activiti
tinymce
rsync
razor
cmd
paw-app
rdf
alpha
azure-media-services
handsontable
etl
resize
flask-wtforms
libtiff
seaborn
solaris-10
amazonsellercentral
autocad-plugin
ml
scriptcs
telerik-reporting
vlsi
dynamic-featured-image
kannel
virtualdub
fifo
webkitspeechrecognition
skia
nameservers
javascriptcore
pdb
fog
commit
revolution-slider
space-complexity
libraries
starteam
graphenedb
unoconv
fedex
janrain
bootstrap-dialog
flashair
node-sass
dotcover
atomicity
datastax-startup
font-size
sqlbulkcopy
sqldf
imanage
time-and-attendance
medium.com
underscore.js-templating
plottable.js
qcustomplot
yaws
xpath-1.0
associative-array
msys
marching-cubes
ruby-2.2
emailrelay
operation
system32
streambase
geonetwork
nsmutabledictionary
dd
asp.net-dynamic-data
rdl
document-classification
xojo
wp-query
htmlcleaner
uv-mapping
jsctypes
hungarian-algorithm
jelly
jquery-knob
nsnetservice
manchester-syntax
enter
fireworks
blackberry-playbook
xtype
sql-server-profiler
xfbml
subviews
icanhaz.js
brewmp

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App