适配TinyInt
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.test.common.utils;
|
package com.test.common.utils;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -40,7 +41,14 @@ public class MySQLExecutor {
|
|||||||
// 获取字段名和字段值
|
// 获取字段名和字段值
|
||||||
String columnName = metaData.getColumnLabel(i);
|
String columnName = metaData.getColumnLabel(i);
|
||||||
Object columnValue = resultSet.getObject(i);
|
Object columnValue = resultSet.getObject(i);
|
||||||
|
int columnType = metaData.getColumnType(i);
|
||||||
|
if (columnType == Types.TINYINT) {
|
||||||
|
row.put(columnName, resultSet.getInt(columnName));
|
||||||
|
} else if (columnType == Types.TIMESTAMP) {
|
||||||
|
row.put(columnName, ((Timestamp) columnValue).toLocalDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||||
|
} else {
|
||||||
row.put(columnName, columnValue);
|
row.put(columnName, columnValue);
|
||||||
|
}
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
columnNameList.add(columnName);
|
columnNameList.add(columnName);
|
||||||
}
|
}
|
||||||
@@ -53,4 +61,17 @@ public class MySQLExecutor {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public static void main(String[] args) {
|
||||||
|
// String url = "jdbc:mysql://47.103.142.5:3306/cmcf-test";
|
||||||
|
// List<String> columnNameList = new ArrayList<>();
|
||||||
|
// List<Map<String, Object>> resultMapList = MySQLExecutor.executeQuery("select * from test_task t", url, "test", "Test123@", columnNameList);
|
||||||
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
// try {
|
||||||
|
// String result = objectMapper.writeValueAsString(resultMapList);
|
||||||
|
// System.out.println(result);
|
||||||
|
// } catch (JsonProcessingException e) {
|
||||||
|
// throw new RuntimeException(e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user