Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can i make a 2 layer structure?

0 views
Skip to first unread message

Stefan Meyer

unread,
Nov 13, 2009, 7:50:17 AM11/13/09
to
Hello i try the code below but in the for each i get an error. now
datatype allowed

How can i fix this i need two layers

public static HashMap<String, HashMap> data = new
LinkedHashMap<String, HashMap>();


public void getConfig() {
String strSQL = "";
JDb db = new JDb();
db.ConnectDb();
strSQL = "SELECT " +
" CID, " +
" ckey," +
" cvalue," +
" cdescription " +
"FROM " +
" config " +
"ORDER BY " +
" ckey";
db.makeQuery(strSQL);
try {
while (db.rs.next()) {
HashMap<String, String> c = new LinkedHashMap<String,
String>();
c.clear();
c.put("CID", db.rs.getString("CID"));
c.put("ckey", db.rs.getString("ckey"));
c.put("cvalue", db.rs.getString("cvalue"));
c.put("cdescription", db.rs.getString("cdescription"));
data.put("sys",c);
}
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.toString());
}

// Einzelwert
HashMap item = (HashMap) data.get(0);
System.out.println("Einzelwerttest: " +item.get(""));

// ALle Werte ausgeben
for (HashMap<String, HashMap> c : data) {
for (String key : c.keySet()) {
System.out.println(key + ": " + c.get(key));
}
}

// System.out.println(((HashMap)data.get(0)).get("Marke"));
// System.out.println(((HashMap) data.get(0)).get("Marke"));
// System.out.println(data);

}
}

Joshua Cranmer

unread,
Nov 13, 2009, 8:07:40 AM11/13/09
to
On 11/13/2009 07:50 AM, Stefan Meyer wrote:
> Hello i try the code below but in the for each i get an error. now
> datatype allowed
>
> How can i fix this i need two layers
>
> public static HashMap<String, HashMap> data = new LinkedHashMap<String,
> HashMap>();

public static Map<String, Map<String, String>> data;

That works surprisingly well.

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

0 new messages