The Dataclass is this
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package my.config;
/**
*
* @author smiefert
*/
public class JConfigEntry {
Integer CID;
String ckey, cvalue, cdescription;
// Alles lᅵschen
public void clear() {
this.setCID(0);
this.setCkey("");
this.setCvalue("");
this.setCdescription("");
}
// Setter
public void setCID(Integer CID) {
this.CID = CID;
}
public void setCkey(String ckey) {
this.ckey = ckey;
}
public void setCvalue(String cvalue) {
this.cvalue = cvalue;
}
public void setCdescription(String cdescription) {
this.cdescription = cdescription;
}
// Getter
public Integer getCID() {
return this.CID;
}
public String getCkey() {
return this.ckey;
}
public String getCvalue() {
return this.cvalue;
}
public String getCdescription() {
return this.cdescription;
}
}
and i call it here
public class JConfig {
// public Collection c = new LinkedList();
// public Collection c = new ArrayList();
// public Collection c = new LinkedList();
// public Collection c = new HashSet();
// public HashMap c = new HashMap ();
// public HashMap c = new LinkedHashMap ();
// public ArrayList data = new ArrayList();
// public static ArrayList<HashMap<String, String>> data = new
ArrayList<HashMap<String, String>>();
public static HashMap<String, HashMap> data = new
LinkedHashMap<String, HashMap>();
public void JConfig() {
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()) {
JConfigEntry c = new JConfigEntry();
c.setCID(db.rs.getInt("CID"));
c.setCkey(db.rs.getString("ckey"));
c.setCvalue(db.rs.getString("cvalue"));
c.setCdescription(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));
}
}
}
}
i get alwys this error: cannot find symbol at this line
data.put("sys", c);
Whats wrong ?
[...]
> public class JConfigEntry { ... }
[...]
> public static HashMap<String, HashMap> data = new
> LinkedHashMap<String, HashMap>();
[...]
> JConfigEntry c = new JConfigEntry();
[...]
> data.put("sys", c);
[...]
>
> i get alwys this error: cannot find symbol at this line
>
> data.put("sys", c);
>
> Whats wrong ?
Well, data is a HashMap<String, HashMap>, but you're trying to invoke
put with a String and a JConfigEntry. Perhaps you want the variable data
to be a Map <String, JConfigEntry>?
Here's a simple example of a the structure proposed by Joshua Cranmer in
an adjacent thread:
<code>
import java.util.HashMap;
import java.util.Map;
/**
* @author John B. Matthews
*/
public class MapTest {
public static void main(String[] args) {
Map<String, Map<String, String>> map =
new HashMap<String, Map<String, String>>();
Map<String, String> m1 = new HashMap<String, String>();
m1.put("One", "Alpha");
m1.put("Two", "Beta");
map.put("Ordinals", m1);
Map<String, String> m2 = new HashMap<String, String>();
m2.put("One", "Aleph");
m2.put("Two", "Beth");
map.put("Cardinals", m2);
Map<String, String> m3 = new HashMap<String, String>();
m3.put("One", "Alpher");
m3.put("Two", "Bethe");
map.put("Physicists", m3);
printMap(map);
}
private static void printMap(Map<String, Map<String, String>> map) {
for (Map.Entry entry : map.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
System.out.println();
}
}
</code>
<console>
Ordinals {One=Alpha, Two=Beta}
Physicists {One=Alpher, Two=Bethe}
Cardinals {One=Aleph, Two=Beth}
</console>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
Watch your spelling.
> ...
> public class JConfig {
> public static HashMap<String, HashMap> data = new
> LinkedHashMap<String, HashMap>();
> ...
> try {
> while (db.rs.next()) {
> JConfigEntry c = new JConfigEntry();
> c.setCID(db.rs.getInt("CID"));
> c.setCkey(db.rs.getString("ckey"));
> c.setCvalue(db.rs.getString("cvalue"));
> c.setCdescription(db.rs.getString("cdescription"));
>
> data.put("sys", c);
> }
> } catch (SQLException e) {
> System.out.println("SQL Exception: " + e.toString());
> }
> ...
> i [sic] get alwys this error: cannot find symbol at this line
>
Copy and paste error messages for Usenet posts; don't paraphrase.
> data.put("sys", c);
>
> Whats wrong ?
Many things are wrong, but in particular for the error about which you
ask, 'data' is defined as a
'HashMap<String, HashMap> ' (which lacks complete generic
typification), but you are calling put with a
'( String, JConfigEntry )' argument pair. There is not a definition
for the symbol 'put( String, JConfigEntry )' so the compiler complains
that it cannot find that symbol.
--
Lew
> public static HashMap<String, HashMap> data = new LinkedHashMap<String, HashMap>();
> JConfigEntry c = new JConfigEntry();
> data.put("sys", c);
Those are the three relevant lines.
You redefine things so often, I think you have tripped over yourself.
Make up your mind what sort of animal data is.
Is it a HashMap<String, HashMap> or a HashMap<String, JConfigEntry>?
Some general thoughts:
It is unusual to only partially use generics. Maybe you meant
something on the order of
HashMap<String, HashMap<String, JConfigEntry>>
It is unusual to have a HashMap of HashMaps. You could get much the
same effect with a single HashMap with a two-field key object that
implements hash, and equals.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Without deviation from the norm, progress is not possible.
~ Frank Zappa (born: 1940-12-21 died: 1993-12-04 at age: 52)