I'm currently having a problem with displaying Row Values from MS Access to Java jLabel.
I have a Ms Access database with the name Table
with 3 rows i just want to display the rows in java jlabels
see the picture but it shows the first row and I'm currently confused Thanks!
try {
resultset.first();
String name = "Name: ";
String dmg = "Damage: ";
String type = "Ammo Type: ";
//row1
weapon1.setText(name+resultset.getString("weapons"));
weapon1dmg.setText(dmg+resultset.getString("weaponDMG"));
weapon1type.setText(type+resultset.getString("weaponAmmoType"));
//row2
weapon2.setText(name+resultset.getString("weapons"));
weapon2dmg.setText(dmg+resultset.getString("weaponDMG"));
weapon2type.setText(type+resultset.getString("weaponAmmoType"));
//row3
weapon3.setText(name+resultset.getString("weapons"));
weapon3dmg.setText(dmg+resultset.getString("weaponDMG"));
weapon3type.setText(type+resultset.getString("weaponAmmoType"));
}
You need to loop through the result set, otherwise you are reading the first row again and again.
try {
String name = "Name: ";
String dmg = "Damage: ";
String type = "Ammo Type: ";
int count = 0;
while(resultset.next){
count++
if(count == 1){
weapon1.setText(name+resultset.getString("weapons"));
weapon1dmg.setText(dmg+resultset.getString("weaponDMG"));
weapon1type.setText(type+resultset.getString("weaponAmmoType"));
}else if(count == 2){
weapon2.setText(name+resultset.getString("weapons"));
weapon2dmg.setText(dmg+resultset.getString("weaponDMG"));
weapon2type.setText(type+resultset.getString("weaponAmmoType"));
}else if(count == 3)
weapon3.setText(name+resultset.getString("weapons"));
weapon3dmg.setText(dmg+resultset.getString("weaponDMG"));
weapon3type.setText(type+resultset.getString("weaponAmmoType"));
}
There should be a better way of doing it, but I don't have access to the rest of your code to see how to simplify it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.