Ich versuche, meine HashMap in eine Access-Datenbank einzufügen, aber ich bekomme immer Fehler. Hier ist mein Code:Wie Sie eine HashMap in eine Datenbank in Java einfügen
for (Entry<String, String> entry : mapImpedanceAll.entrySet()) {
prep1 = entry.getKey().replaceAll("\\s", "_");
prep1=prep1.replace(":","");
prep1=prep1.replace("<","LessThan");
prep1=prep1.replaceAll("\\." ,"");
prep1=prep1.replaceAll("\\(s\\)" ,"");
prep1=prep1.replaceAll(",$" ,"");
prep1=prep1.replaceAll("%" ,"");
prep1=prep1.replace("-" ,"_");
prep1=prep1.replace("_" ,"");
if(dbColNames.contains(prep1)){
try {
Statement qu = null;
qu =conn.createStatement();
String stg = "INSERT INTO Impedance2 "+prep1+" VALUES('"+entry.getValue()+"')";
qu.execute(stg);
} catch (Exception e) {
e.printStackTrace();
}
}
}
und hier ist der Fehler:
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.4 row column count mismatch
Ich bin sicher, es ist etwas mit der Aussage String stg = "INSERT INTO Impedance2 "+prep1+" VALUES('"+entry.getValue()+"')";
zu tun, aber ich habe gespielt mit ihm herum und es immer noch Reisen oben.
dbColNames
ist ein Array von bestehenden Datenbankspaltennamen, damit ich gegen sie überprüfen, bevor die HashMap