java - How can I get a Specific Item Out of a List<Map<String, Object>> -


when run code:

list<map<string, object>> beforedelete = query("select count(*) wp_announcement announcement_id =" + announcementid, null);  system.out.println("this count : " + beforedelete.get(0)); 

i result:

this count : {c1=1} 

how can 1, instead of {c1=1}?

if know structure of returned map going show, value inside c1 key this:

int val = ((integer)beforedelete.get(0).get("c1")).intvalue(); 

add safety checks ensure result has 1 element, , initial element has key of "c1" maps java.lang.integer.

this should safe long query fixed. if query comes source outside of control, need work out other way access result.

note: assuming query makes rdbms, should parameterize query avoid injection attacks.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -

Why does a .NET 4.0 program produce a system.unauthorizedAccess error on a Windows Server 2012 machine with .NET 4.5 installed? -