1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
prop.put("charSet", "utf-8"); prop.put("user", ""); prop.put("password", ""); PreparedStatement ps = null; Statement stmt = null; ResultSet rs = null; try { Class.forName("net.ucanaccess.jdbc.UcanaccessDriver"); Connection conn = DriverManager.getConnection("jdbc:ucanaccess://" + accessUrl, "账号", "密码"); stmt = conn.createStatement(); rs = stmt.executeQuery(sql); ResultSetMetaData data = rs.getMetaData(); while (rs.next()) { Map<String, Object> map = new HashMap<>(16); for (int i = 1; i <= data.getColumnCount(); i++) { String columnName = data.getColumnName(i); String columnValue = rs.getString(i); map.put(columnName, columnValue); } mapList.add(map); } conn.close(); } catch (Exception e) { e.printStackTrace(); } return mapList; }
|