Advertisement
Guest User

Untitled

a guest
Nov 21st, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. 16 9:27:41 PM org.apache.catalina.core.StandardWrapperValve invoke
  2. SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: Invalid value "1000" for parameter "resultSetHoldability" [90008-193]] with root cause
  3. org.h2.jdbc.JdbcSQLException: Invalid value "1000" for parameter "resultSetHoldability" [90008-193]
  4. at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
  5. at org.h2.message.DbException.get(DbException.java:179)
  6. at org.h2.message.DbException.getInvalidValueException(DbException.java:228)
  7. at org.h2.jdbc.JdbcConnection.checkHoldability(JdbcConnection.java:1445)
  8. at org.h2.jdbc.JdbcConnection.createStatement(JdbcConnection.java:261)
  9. at com.project.x.api.utils.PsqlUtils.getStatement(PsqlUtils.java:146)
  10. at com.project.x.api.utils.PsqlUtils.sqltoList(PsqlUtils.java:51)
  11. at com.project.x.api.utils.PsqlUtils.sqltoJson(PsqlUtils.java:79)
  12. at com.project.x.api.dao.UserDao.getUserCnt(UserDao.java:192)
  13.  
  14. @Component
  15. public class PsqlUtils {
  16.  
  17. final static Logger log = LoggerFactory.getLogger(PsqlUtils.class);
  18.  
  19. //Config
  20. private final String db_url;
  21. private final String db_username;
  22. private final String db_password;
  23. @Autowired
  24. public PsqlUtils(@Value("${db.url}") String db_url, @Value("${db.username}") String db_username, @Value("${db.password}") String db_password) {
  25. this.db_url = db_url;
  26. this.db_username = db_username;
  27. this.db_password = db_password;
  28. }
  29.  
  30.  
  31.  
  32. public List<Map<String, Object>> sqltoList(final String sql) {
  33. log.debug("SqltoJson sql : {}", sql);
  34. String jsonData;
  35.  
  36. Connection connection;
  37. Statement statement;
  38. ResultSet resultSet;
  39. final List<Map<String, Object>> objList = new ArrayList<>();
  40.  
  41. try {
  42. connection = getConnection();
  43. connection.setAutoCommit(false);
  44. statement = getStatement(connection);
  45. resultSet = executeQuery(statement, sql);
  46.  
  47. final int columnCount = resultSet.getMetaData().getColumnCount();
  48.  
  49. while (resultSet.next()) {
  50. final Map<String, Object> rowData = new HashMap<>();
  51. for (int column = 1; column <= columnCount; ++column) {
  52. rowData.put(resultSet.getMetaData().getColumnName(column), resultSet.getObject(column));
  53. }
  54. objList.add(rowData);
  55. }
  56.  
  57. resultSet.close();
  58. statement.close();
  59. connection.close();
  60.  
  61.  
  62. }catch (SQLException | IOException e){
  63. throw new RuntimeException(e.getMessage(), e);
  64. }
  65. return objList;
  66. }
  67.  
  68. public String sqltoJson(final String sql) throws SQLException {
  69. log.debug("SqltoJson sql : {}", sql);
  70. String jsonData;
  71.  
  72. List<Map<String, Object>> objList = sqltoList(sql);
  73.  
  74. if (!objList.isEmpty()) {
  75. final ObjectMapper mapper = new ObjectMapper();
  76. try {
  77. jsonData = mapper.writeValueAsString(objList);
  78. } catch (JsonProcessingException e) {
  79. throw new RuntimeException(e.getMessage(), e);
  80. }
  81. } else {
  82. jsonData = "[]";
  83. }
  84.  
  85.  
  86.  
  87. return jsonData;
  88. }
  89.  
  90. public String sqltoJsonObject(final String sql) throws SQLException {
  91. log.debug("SqltoJson sql : {}", sql);
  92.  
  93. String jsonData;
  94.  
  95. Connection connection;
  96. Statement statement;
  97. ResultSet resultSet;
  98.  
  99. try {
  100. connection = getConnection();
  101. connection.setAutoCommit(false);
  102. statement = getStatement(connection);
  103. resultSet = executeQuery(statement, sql);
  104.  
  105. final int columnCount = resultSet.getMetaData().getColumnCount();
  106. final List<Map<String, Object>> objList = new ArrayList<>();
  107.  
  108. resultSet.next();
  109. final Map<String, Object> rowData = new HashMap<>();
  110. for (int column = 1; column <= columnCount; ++column) {
  111. rowData.put(resultSet.getMetaData().getColumnName(column), resultSet.getObject(column));
  112. }
  113. objList.add(rowData);
  114.  
  115. if (!objList.isEmpty()) {
  116. final ObjectMapper mapper = new ObjectMapper();
  117. jsonData = mapper.writeValueAsString(rowData);
  118. } else {
  119. jsonData = "[]";
  120. }
  121.  
  122.  
  123. } catch (SQLException | IOException e){
  124. throw new RuntimeException(e.getMessage(), e);
  125. }
  126. return jsonData;
  127. }
  128.  
  129. public Connection getConnection() throws IOException, SQLException {
  130.  
  131. //final Properties props = readProperties(propertiesPath);
  132. final Connection connection = DriverManager.getConnection(db_url, db_username, db_password);
  133. connection.setAutoCommit(false);
  134. return connection;
  135. }
  136.  
  137.  
  138. public Statement getStatement(Connection connection) throws SQLException {
  139. final Statement statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.FETCH_FORWARD);
  140. statement.setFetchSize(0);
  141. return statement;
  142. }
  143.  
  144. public ResultSet executeQuery(Statement statement, String query) throws SQLException {
  145. log.debug("sql : {}", query);
  146. return statement.executeQuery(query);
  147. }
  148.  
  149. public Statement getStatementExecute(Connection connection) throws SQLException {
  150. return connection.createStatement();
  151. }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement