aspose file tools*
The moose likes JDBC and the fly likes Setting checkbox from database. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Setting checkbox from database." Watch "Setting checkbox from database." New topic
Author

Setting checkbox from database.

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477


Hi Folks,
Im trying to fetch data from database and set the value inn my fields which includes a checkbox.
Im able to successfully retreive values from the database and also able to populate my text boxes.
But cant seem to check a checkbox if its been set .


Any help on how I could set the checkbox value ?

Learning and Learning!-- Java all the way!
joy b chakravarty
Ranch Hand

Joined: May 16, 2011
Posts: 62

For String comparisons use the equals method


Cheers, Joy [SCJP 1.4, SCBCD 5.0]
get high on alcohol, algorithm or both
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Thanks Joy!
Yup!
Missed that !my bad!.
but checkbox is still not being checked at the front end. What value should I be setting it to so that at the front end I can see it as checked when active is "1" ?
Arun Chidam
Ranch Hand

Joined: May 08, 2006
Posts: 79
if(rs.getString("isactive")=="1".trim()){//checkbox value in database is set to 1 if checked.
domain.setstatusActive("checked");

}


If you are using isActive column as boolean then use appropriate datatype(use Boolean for Oracle and Bit for Sqlserver) rather than String which consumes more memory and might lead to invalid boolean check. Modify your IF condition to getBoolean("columnName") which checks the returned value as either true or false.

In regards to your query on "not being checked at the front end", please run it in debug mode and check the IF condition?, if it satisfies then check if any ther control overriddes your checkbox condition?


SCJP 1.4, SCWCD 1.4
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Thanks for the tip ! Arun . Solved the issue , added a c:if to my jsp to set checked = true when '1'.
Arun Chidam
Ranch Hand

Joined: May 08, 2006
Posts: 79
Thanks Vic for sharing your results
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting checkbox from database.