List of usage examples for java.sql Connection isClosed
boolean isClosed() throws SQLException;
Connection
object has been closed. From source file:com.cws.esolutions.security.dao.userauth.impl.SQLAuthenticator.java
/** * @see com.cws.esolutions.security.dao.userauth.interfaces.Authenticator#obtainOtpSecret(java.lang.String, java.lang.String) *//*from w w w. java2 s .c o m*/ public synchronized String obtainOtpSecret(final String userName, final String userGuid) throws AuthenticatorException { final String methodName = SQLAuthenticator.CNAME + "#obtainOtpSecret(final String userName, final String userGuid) throws AuthenticatorException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", userName); DEBUGGER.debug("Value: {}", userGuid); } String otpSecret = null; Connection sqlConn = null; ResultSet resultSet = null; CallableStatement stmt = null; try { sqlConn = SQLAuthenticator.dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{CALL getOtpSecret(?, ?)}"); stmt.setString(1, userGuid); // guid stmt.setString(2, userName); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (stmt.execute()) { resultSet = stmt.getResultSet(); if (DEBUG) { DEBUGGER.debug("ResultSet: {}", resultSet); } if (resultSet.next()) { resultSet.first(); otpSecret = resultSet.getString(1); } } } catch (SQLException sqx) { throw new AuthenticatorException(sqx.getMessage(), sqx); } finally { try { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if (!(sqlConn == null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } catch (SQLException sqx) { throw new AuthenticatorException(sqx.getMessage(), sqx); } } return otpSecret; }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateProcedureController.java
@RequestMapping(value = "/createprocedure", method = RequestMethod.POST) public String createProcedureAction(@ModelAttribute("procedureAttribute") NewProcedure procedureAttribute, Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {/* www .j av a 2 s .c o m*/ Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } logger.debug("Received request to action an event for create Procedure"); String schema = procedureAttribute.getSchemaName().trim(); if (schema.length() == 0) { schema = (String) session.getAttribute("schema"); } logger.debug("New Procedure schema name = " + schema); logger.debug("New Procedure name = " + procedureAttribute.getProcedureName()); // perform some action here with what we have String submit = request.getParameter("pSubmit"); if (submit != null) { if (submit.equalsIgnoreCase("Parameter(s)")) { int cols = Integer.parseInt(request.getParameter("numParams")); int numParams = Integer.parseInt((String) session.getAttribute("numParams")); numParams = numParams + cols; session.setAttribute("numParams", "" + numParams); model.addAttribute("numParams", numParams); } else { // build create HDFS Store SQL StringBuffer createProcedure = new StringBuffer(); createProcedure .append("CREATE PROCEDURE " + schema + "." + procedureAttribute.getProcedureName() + " \n"); String[] parameterTypes = request.getParameterValues("parameter_type[]"); String[] parameterNames = request.getParameterValues("parameter_name[]"); String[] dataTypes = request.getParameterValues("data_type[]"); String[] columnPrecision = request.getParameterValues("column_precision[]"); logger.debug("parameterTypes = " + Arrays.toString(parameterTypes)); logger.debug("parameterNames = " + Arrays.toString(parameterNames)); logger.debug("dataTypes = " + Arrays.toString(dataTypes)); logger.debug("columnPrecision = " + Arrays.toString(columnPrecision)); int i = 0; int size = 0; if (parameterNames != null) { size = parameterNames.length; for (String parameterName : parameterNames) { if (i == 0) { createProcedure.append("("); } createProcedure.append(parameterTypes[i] + " " + parameterName + " " + dataTypes[i]); if (columnPrecision[i].length() != 0) { createProcedure.append("(" + columnPrecision[i] + ")"); } i++; if (i < size) { createProcedure.append(", \n"); } } if (i >= 1) { createProcedure.append(") \n"); } } if (!checkIfParameterEmpty(request, "language")) { createProcedure.append("LANGUAGE " + procedureAttribute.getLanguage() + " \n"); } if (!checkIfParameterEmpty(request, "parameterStyle")) { createProcedure.append("PARAMETER STYLE " + procedureAttribute.getParameterStyle() + " \n"); } if (!checkIfParameterEmpty(request, "sqlAccess")) { createProcedure.append(procedureAttribute.getSqlAccess() + " \n"); } if (!checkIfParameterEmpty(request, "dynamicResultsets")) { createProcedure .append("DYNAMIC RESULT SETS " + procedureAttribute.getDynamicResultsets() + " \n"); } createProcedure.append("EXTERNAL NAME '" + procedureAttribute.getExternalName() + "'\n"); if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating Procedure as -> " + createProcedure.toString()); result = GemFireXDWebDAOUtil.runCommand(createProcedure.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Create Procedure SQL as follows as -> " + createProcedure.toString()); model.addAttribute("sql", createProcedure.toString()); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, procedureAttribute.getProcedureName())); ServletOutputStream out = response.getOutputStream(); out.println(createProcedure.toString()); out.close(); return null; } } } // This will resolve to /WEB-INF/jsp/create-procedure.jsp return "create-procedure"; }
From source file:com.cws.us.pws.dao.impl.CareersReferenceDAOImpl.java
/** * @see com.cws.us.pws.dao.interfaces.ICareersReferenceDAO#getCareerData(String, String) throws SQLException *//* w w w . j a v a2 s .com*/ @Override public List<Object> getCareerData(final String reqId, final String lang) throws SQLException { final String methodName = ICareersReferenceDAO.CNAME + "#getCareerData(final int reqId, final String lang) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", reqId); DEBUGGER.debug("Value: {}", lang); } Connection sqlConn = null; ResultSet resultSet = null; List<Object> results = null; CallableStatement stmt = null; try { sqlConn = this.dataSource.getConnection(); if (DEBUG) { DEBUGGER.debug("Connection: {}", sqlConn); } if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain connection to application datasource"); } stmt = sqlConn.prepareCall("{ CALL getCareerData(?, ?) }"); stmt.setString(1, reqId); stmt.setString(2, lang); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (!(stmt.execute())) { throw new SQLException("PreparedStatement is null. Cannot execute."); } resultSet = stmt.getResultSet(); if (DEBUG) { DEBUGGER.debug("ResultSet: {}", resultSet); } if (resultSet.next()) { resultSet.beforeFirst(); results = new ArrayList<Object>(); while (resultSet.next()) { results.add(resultSet.getString(1)); // REQ_ID results.add(resultSet.getDate(2)); // POST_DATE results.add(resultSet.getDate(3)); // UNPOST_DATE results.add(resultSet.getString(4)); // JOB_TITLE results.add(resultSet.getString(5)); // JOB_SHORT_DESC results.add(resultSet.getString(6)); // JOB_DESCRIPTION } if (DEBUG) { DEBUGGER.debug("results: {}", results); } } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); throw new SQLException(sqx.getMessage(), sqx); } finally { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } if (DEBUG) { DEBUGGER.debug("results: {}", results); } return results; }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateIndexController.java
@RequestMapping(value = "/createindex", method = RequestMethod.POST) public String createIndexAction(@ModelAttribute("indexAttribute") NewIndex indexAttribute, Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {// w w w . j ava2 s.c om Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } logger.debug("Received request to action an event for create index"); String tabName = indexAttribute.getTableName(); String schema = indexAttribute.getSchemaName(); String unique = indexAttribute.getUnique(); String idxName = indexAttribute.getIndexName(); String submit = request.getParameter("pSubmit"); String[] selectedColumns = request.getParameterValues("selected_column[]"); String[] indexOrder = request.getParameterValues("idxOrder[]"); String[] position = request.getParameterValues("position[]"); logger.debug("selectedColumns = " + Arrays.toString(selectedColumns)); logger.debug("indexOrder = " + Arrays.toString(indexOrder)); logger.debug("position = " + Arrays.toString(position)); IndexDAO indexDAO = GemFireXDWebDAOFactory.getIndexDAO(); List<IndexColumn> columns = indexDAO.retrieveIndexColumns(schema, tabName, (String) session.getAttribute("user_key")); StringBuffer createIndex = new StringBuffer(); if (unique.equalsIgnoreCase("Y")) { createIndex.append("create unique index " + idxName + " on " + schema + "." + tabName + " "); } else { createIndex.append("create index " + idxName + " on " + schema + "." + tabName + " "); } createIndex.append("("); if (selectedColumns != null) { int i = 0; Map<String, IndexDefinition> cols = new HashMap<String, IndexDefinition>(); for (String column : selectedColumns) { String columnName = column.substring(0, column.indexOf("_")); String index = column.substring(column.indexOf("_") + 1); String pos = position[Integer.parseInt(index) - 1]; if (pos.trim().length() == 0) { pos = "" + i; } logger.debug("Column = " + columnName + ", indexOrder = " + indexOrder[Integer.parseInt(index) - 1] + ", position = " + pos); IndexDefinition idxDef = new IndexDefinition(columnName, indexOrder[Integer.parseInt(index) - 1]); cols.put("" + pos, idxDef); i++; } // sort map and create index now SortedSet<String> keys = new TreeSet<String>(cols.keySet()); int length = keys.size(); i = 0; for (String key : keys) { IndexDefinition idxDefTemp = cols.get(key); if (i == (length - 1)) { createIndex.append(idxDefTemp.getColumnName() + " " + idxDefTemp.getOrderType() + ")"); } else { createIndex.append(idxDefTemp.getColumnName() + " " + idxDefTemp.getOrderType() + ", "); } i++; } } if (!checkIfParameterEmpty(request, "caseSensitive")) { createIndex.append(" " + request.getParameter("caseSensitive") + "\n"); } if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating index as -> " + createIndex.toString()); result = GemFireXDWebDAOUtil.runCommand(createIndex.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); model.addAttribute("tabName", tabName); model.addAttribute("tableSchemaName", schema); model.addAttribute("columns", columns); model.addAttribute("schema", schema); session.removeAttribute("numColumns"); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Index SQL as follows as -> " + createIndex.toString()); model.addAttribute("sql", createIndex.toString()); model.addAttribute("tabName", tabName); model.addAttribute("tableSchemaName", schema); model.addAttribute("columns", columns); model.addAttribute("schema", schema); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, idxName)); ServletOutputStream out = response.getOutputStream(); out.println(createIndex.toString()); out.close(); return null; } // This will resolve to /WEB-INF/jsp/create-index.jsp return "create-index"; }
From source file:com.cws.us.pws.dao.impl.CareersReferenceDAOImpl.java
/** * @see com.cws.us.pws.dao.interfaces.ICareersReferenceDAO#getCareerList(String) throws SQLException *//* w w w .java 2 s . co m*/ @Override public List<Object[]> getCareerList(final String lang) throws SQLException { final String methodName = ICareersReferenceDAO.CNAME + "#getCareerList(final String lang) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", lang); } Connection sqlConn = null; ResultSet resultSet = null; CallableStatement stmt = null; List<Object[]> results = null; try { sqlConn = this.dataSource.getConnection(); if (DEBUG) { DEBUGGER.debug("Connection: {}", sqlConn); } if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain connection to application datasource"); } stmt = sqlConn.prepareCall("{ CALL getCareersList(?) }"); stmt.setString(1, lang); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (!(stmt.execute())) { throw new SQLException("PreparedStatement is null. Cannot execute."); } resultSet = stmt.getResultSet(); if (DEBUG) { DEBUGGER.debug("ResultSet: {}", resultSet); } if (resultSet.next()) { resultSet.beforeFirst(); results = new ArrayList<Object[]>(); while (resultSet.next()) { Object[] data = new Object[] { resultSet.getString(1), // REQ_ID resultSet.getString(2), // POST_DATE resultSet.getString(3), // UNPOST_DATE resultSet.getString(4), // JOB_TITLE resultSet.getBigDecimal(5), // JOB_SHORT_DESC resultSet.getString(6), // JOB_DESCRIPTION }; results.add(data); } if (DEBUG) { DEBUGGER.debug("results: {}", results); } } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); throw new SQLException(sqx.getMessage(), sqx); } finally { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } if (DEBUG) { DEBUGGER.debug("results: {}", results); } return results; }
From source file:com.adaptris.jdbc.connection.FailoverDatasourceTest.java
@Test public void testDataSourceWithPassword() throws Exception { FailoverDataSource fds = new FailoverDataSource(createProperties()); Connection con = fds.getConnection("MyUser", "MyPassword"); try {//from www. j a v a 2s . c om assertFalse(con.isClosed()); createTables(con); } finally { JdbcUtil.closeQuietly(con); fds.destroy(); } }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateFunctionController.java
@RequestMapping(value = "/createfunction", method = RequestMethod.POST) public String createFunctionAction(@ModelAttribute("functionAttribute") NewFunction functionAttribute, Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {//from w w w .j ava 2 s.c om Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } logger.debug("Received request to action an event for create Procedure"); String schema = functionAttribute.getSchemaName().trim(); if (schema.length() == 0) { schema = (String) session.getAttribute("schema"); } logger.debug("New Function schema name = " + schema); logger.debug("New Function name = " + functionAttribute.getFunctionName()); // perform some action here with what we have String submit = request.getParameter("pSubmit"); if (submit != null) { if (submit.equalsIgnoreCase("Parameter(s)")) { int cols = Integer.parseInt(request.getParameter("numParams")); int numParams = Integer.parseInt((String) session.getAttribute("numParams")); numParams = numParams + cols; session.setAttribute("numParams", "" + numParams); model.addAttribute("numParams", numParams); } else { // build create HDFS Store SQL StringBuffer createFunction = new StringBuffer(); createFunction .append("CREATE FUNCTION " + schema + "." + functionAttribute.getFunctionName() + " \n"); String[] parameterTypes = request.getParameterValues("parameter_type[]"); String[] parameterNames = request.getParameterValues("parameter_name[]"); String[] dataTypes = request.getParameterValues("data_type[]"); String[] columnPrecision = request.getParameterValues("column_precision[]"); logger.debug("parameterTypes = " + Arrays.toString(parameterTypes)); logger.debug("parameterNames = " + Arrays.toString(parameterNames)); logger.debug("dataTypes = " + Arrays.toString(dataTypes)); logger.debug("columnPrecision = " + Arrays.toString(columnPrecision)); int i = 0; int size = 0; if (parameterNames != null) { size = parameterNames.length; for (String parameterName : parameterNames) { if (i == 0) { createFunction.append("("); } createFunction.append(parameterName + " " + dataTypes[i]); if (columnPrecision[i].length() != 0) { createFunction.append("(" + columnPrecision[i] + ")"); } i++; if (i < size) { createFunction.append(", \n"); } } if (i >= 1) { createFunction.append(") \n"); } } createFunction.append("RETURNS " + functionAttribute.getReturnType()); if (functionAttribute.getReturnPrecision().trim().length() != 0) { createFunction.append("(" + functionAttribute.getReturnPrecision() + ") \n"); } else { createFunction.append(" \n"); } if (!checkIfParameterEmpty(request, "language")) { createFunction.append("LANGUAGE " + functionAttribute.getLanguage() + " \n"); } createFunction.append("EXTERNAL NAME '" + functionAttribute.getExternalName() + "' \n"); if (!checkIfParameterEmpty(request, "parameterStyle")) { createFunction.append("PARAMETER STYLE " + functionAttribute.getParameterStyle() + " \n"); } if (!checkIfParameterEmpty(request, "sqlAccess")) { createFunction.append(functionAttribute.getSqlAccess() + " \n"); } if (!checkIfParameterEmpty(request, "ifNull")) { createFunction.append(functionAttribute.getIfNull() + " \n"); } if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating Function as -> " + createFunction.toString()); result = GemFireXDWebDAOUtil.runCommand(createFunction.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); model.addAttribute("returnType", functionAttribute.getReturnType()); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Create Function SQL as follows as -> " + createFunction.toString()); model.addAttribute("sql", createFunction.toString()); model.addAttribute("returnType", functionAttribute.getReturnType()); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, functionAttribute.getFunctionName())); ServletOutputStream out = response.getOutputStream(); out.println(createFunction.toString()); out.close(); return null; } } } // This will resolve to /WEB-INF/jsp/create-function.jsp return "create-function"; }
From source file:pivotal.au.se.gemfirexdweb.controller.ProcController.java
@RequestMapping(value = "/procs", method = RequestMethod.POST) public String performProcAction(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {/*from www . ja v a2s . c o m*/ Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } int startAtIndex = 0, endAtIndex = 0; String schema = null; Result result = new Result(); List<StoredProc> procs = null; logger.debug("Received request to perform an action on the procs"); String procType = request.getParameter("procType"); logger.debug("procType = " + procType); String selectedSchema = request.getParameter("selectedSchema"); logger.debug("selectedSchema = " + selectedSchema); if (selectedSchema != null) { schema = selectedSchema; } else { schema = (String) session.getAttribute("schema"); } logger.debug("schema = " + schema); StoredProcDAO procDAO = GemFireXDWebDAOFactory.getStoredProcDAO(); if (request.getParameter("search") != null) { procs = procDAO.retrieveProcList(schema, (String) request.getParameter("search"), (String) request.getParameter("procType"), (String) session.getAttribute("user_key")); model.addAttribute("search", (String) request.getParameter("search")); } else { String[] tableList = request.getParameterValues("selected_proc[]"); String commandStr = request.getParameter("submit_mult"); logger.debug("tableList = " + Arrays.toString(tableList)); logger.debug("command = " + commandStr); // start actions now if tableList is not null if (tableList != null) { List al = new ArrayList<Result>(); for (String procName : tableList) { result = null; result = procDAO.simpleprocCommand(schema, procName, commandStr, request.getParameter("procType").equals("P") ? "procedure" : "function", (String) session.getAttribute("user_key")); al.add(result); } model.addAttribute("arrayresult", al); } procs = procDAO.retrieveProcList(schema, null, (String) request.getParameter("procType"), (String) session.getAttribute("user_key")); } model.addAttribute("procType", procType); model.addAttribute("records", procs.size()); model.addAttribute("estimatedrecords", procs.size()); UserPref userPref = (UserPref) session.getAttribute("prefs"); if (procs.size() <= userPref.getRecordsToDisplay()) { model.addAttribute("procs", procs); } else { if (request.getParameter("startAtIndex") != null) { startAtIndex = Integer.parseInt(request.getParameter("startAtIndex")); } if (request.getParameter("endAtIndex") != null) { endAtIndex = Integer.parseInt(request.getParameter("endAtIndex")); if (endAtIndex > procs.size()) { endAtIndex = procs.size(); } } else { endAtIndex = userPref.getRecordsToDisplay(); } List subList = procs.subList(startAtIndex, endAtIndex); model.addAttribute("procs", subList); } model.addAttribute("startAtIndex", startAtIndex); model.addAttribute("endAtIndex", endAtIndex); model.addAttribute("schemas", GemFireXDWebDAOUtil.getAllSchemas((String) session.getAttribute("user_key"))); model.addAttribute("chosenSchema", schema); // This will resolve to /WEB-INF/jsp/procs.jsp return "procs"; }
From source file:com.github.shynixn.blockball.bukkit.logic.persistence.context.SqlDbContextImpl.java
/** * Executes a preparedStatement and sets the given parameters to the statement * * @param sql sql// w ww. j a v a 2 s .co m * @param connection connection * @param parameters parameters * @return success * @throws SQLException exception */ public boolean execute(String sql, Connection connection, Object... parameters) throws SQLException { if (sql == null) throw new IllegalArgumentException("Sql cannot be null!"); if (connection == null) throw new IllegalArgumentException("Connection cannot be null!"); if (connection.isClosed()) throw new IllegalArgumentException("Connection is closed. Cannot create statement!"); try (final PreparedStatement preparedStatement = connection.prepareStatement(sql)) { this.setParameters(preparedStatement, parameters); return preparedStatement.execute(); } }
From source file:com.github.shynixn.blockball.bukkit.logic.persistence.context.SqlDbContextImpl.java
/** * Executes a preparedStatement and sets the given parameters to the statement * * @param sql sql// w ww . j a v a 2 s . co m * @param connection connection * @param parameters parameters * @return resultCode * @throws SQLException exception */ public int executeUpdate(String sql, Connection connection, Object... parameters) throws SQLException { if (sql == null) throw new IllegalArgumentException("Sql cannot be null!"); if (connection == null) throw new IllegalArgumentException("Connection cannot be null!"); if (connection.isClosed()) throw new IllegalArgumentException("Connection is closed. Cannot create statement!"); try (final PreparedStatement preparedStatement = connection.prepareStatement(sql)) { this.setParameters(preparedStatement, parameters); return preparedStatement.executeUpdate(); } }