我创建了一个方法 ( getData()) 来从数据库接收数据,这似乎有效。我想要的是只使用 1 个参数,所以该方法应该以className.getData("SELECT * FROM myTable"). 我怎样才能做到这一点?
public List<String> getData(String sql, Map column) {
this.driver();
try {
Connection conn = DriverManager.getConnection(this.url);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
List<String> result = new ArrayList<>();
if (column.containsKey("string")) {
for (Object i : column.values()) {
while (rs.next()) {
result.add(rs.getString(String.valueOf(i)));
}
}
return result;
}
}
catch (SQLException e) {
e.printStackTrace();
}
return null;
}
private void driver() {
// Ensure we have mariadb Driver in classpath
try {
Class.forName("org.mariadb.jdbc.Driver");
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
慕妹3146593
婷婷同学_
相关分类