|
|
|
|
@ -3,6 +3,12 @@ package de.superx.util;
@@ -3,6 +3,12 @@ package de.superx.util;
|
|
|
|
|
import javax.sql.DataSource; |
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.sql.*; |
|
|
|
|
|
|
|
|
|
public final class DbUtils { |
|
|
|
|
|
|
|
|
|
private DbUtils() { } |
|
|
|
|
@ -15,4 +21,27 @@ public final class DbUtils {
@@ -15,4 +21,27 @@ public final class DbUtils {
|
|
|
|
|
|
|
|
|
|
return count != null && count.intValue() > 0; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* Ein resultset in eine Liste aus String-Maps konvertieren |
|
|
|
|
* |
|
|
|
|
* @param ResultSet |
|
|
|
|
* @return List<Map<String, String>> |
|
|
|
|
*/ |
|
|
|
|
public static List<Map<String, String>> resultSetToStringList(ResultSet rs) throws SQLException { |
|
|
|
|
List<Map<String, String>> resultList = new ArrayList<>(); |
|
|
|
|
ResultSetMetaData metaData = rs.getMetaData(); |
|
|
|
|
int columnCount = metaData.getColumnCount(); |
|
|
|
|
|
|
|
|
|
while (rs.next()) { |
|
|
|
|
Map<String, String> row = new HashMap<>(); |
|
|
|
|
for (int i = 1; i <= columnCount; i++) { |
|
|
|
|
String columnName = metaData.getColumnName(i); |
|
|
|
|
String value = rs.getString(i); |
|
|
|
|
row.put(columnName, value); |
|
|
|
|
} |
|
|
|
|
resultList.add(row); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return resultList; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|