我用javascript和Java开发了函数,但是读取数据(获取)时遇到问题,出现意外错误。
此外,当我在邮递员中进行测试时,它会显示:
意外的
此错误:
未捕获的TypeError:无法在dataF读取null的属性'desc' (view_rh.html:586)
当我在Console中进行调试时,它会向我显示数据为空
代码JavaScript:
d3.json("getJson.jsp?dataType=rh", function(data) {
spinner.stop();
allRHJson=data;
select2_data_all = dataF(allRHJson,[],0)[1];
loadJson(null,allRHJson, select2_data_all ) ;
//d3.json(json, loadJson );
});
function dataF(node, leaves, index) {
leaves.push({
id: ++index,
text: node.desc
});
if (node.children) {
for (var i = 0; i < node.children.length; i++) {
index = dataF(node.children[i], leaves, index)[0];
}
}
return [index, leaves];
}
此外,在Java中,当我调试时,它向我显示:
com.microsoft.sqlserver.jdbc.SQLServerException:无效的列名 'ID'。在 com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError
这是我的Java代码的一部分:
connectionString = new Properties();
connectionString.load(input);
String dbURL = connectionString.getProperty("db.connection.string");
Class.forName(connectionString.getProperty("db.connection.driver"));
conn = DriverManager.getConnection(dbURL, connectionString.getProperty("db.connection.user"),
connectionString.getProperty("db.connection.password"));
Statement statement = conn.createStatement();
String queryString = "SELECT ID, ID_PERE, LIBELLE, DATA FROM " + connectionString.getProperty("db.view");
ResultSet rs = statement.executeQuery(queryString);
HashMap<String, Level> h = new HashMap<String, Level>();
Gson gson = new GsonBuilder().create();
while (rs.next()) {
String id = rs.getString(1);
String idPere = rs.getString(2);
String libelle = rs.getString(3);
String data = rs.getString(4);
if (h.get(id) == null)
h.put(id, new Level(id));
if (h.get(idPere) == null)
h.put(idPere, new Level(idPere));
Level n = h.get(id);
Level p = h.get(idPere);
if (p.getChildren() == null)
p.setChildren(new ArrayList<Level>());
n.setDesc(libelle);
LinkedHashMap<String, String> dataMap = new LinkedHashMap<String, String>();
if (data != null) {
dataMap = (LinkedHashMap<String, String>) gson.fromJson("{" + data + "}", dataMap.getClass());
}
n.setData(dataMap);
p.getChildren().add(n);
n.setParent(idPere);
}