mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-09 05:48:20 +00:00
WIP SQL console
This commit is contained in:
parent
198f7166f2
commit
2352bdcdd7
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
package tech.ailef.dbadmin.external.controller;
|
package tech.ailef.dbadmin.external.controller;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.ResultSetMetaData;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -543,9 +545,36 @@ public class DefaultDbAdminController {
|
|||||||
model.addAttribute("activePage", "console");
|
model.addAttribute("activePage", "console");
|
||||||
|
|
||||||
if (query != null) {
|
if (query != null) {
|
||||||
jdbTemplate.execute(query);
|
List<Map<String, Object>> results = jdbTemplate.query(query, (rs, rowNum) -> {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
ResultSetMetaData metaData = rs.getMetaData();
|
||||||
|
int cols = metaData.getColumnCount();
|
||||||
|
|
||||||
|
for (int i = 0; i < cols; i++) {
|
||||||
|
Object o = rs.getObject(i + 1);
|
||||||
|
String columnName = metaData.getColumnName(i + 1);
|
||||||
|
result.put(columnName, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print each map in a tabular format
|
||||||
|
*/
|
||||||
|
for (Map<String, Object> obj : results) {
|
||||||
|
System.out.println("-----------------------------------------------------------");
|
||||||
|
for (String key : obj.keySet()) {
|
||||||
|
System.out.printf("%-20s | %s\n", key, obj.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return "console";
|
return "console";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user