List of usage examples for java.sql Connection prepareCall
CallableStatement prepareCall(String sql) throws SQLException;
CallableStatement
object for calling database stored procedures. From source file:genepi.db.JdbcDataAccessObject.java
public boolean callProcedure(String sql, Object[] params) throws SQLException { Connection connection = null; try {//from w ww. jav a 2 s . c o m connection = database.getDataSource().getConnection(); CallableStatement cstmt = connection.prepareCall(sql); runner.fillStatement(cstmt, params); boolean state = cstmt.execute(); cstmt.close(); connection.close(); return state; } catch (SQLException e) { throw e; } finally { connection.close(); } }
From source file:com.app.uploads.ImageTest.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w. ja v a2s. c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String type = ""; CallableStatement pro; String UPLOAD_DIRECTORY = getServletContext().getRealPath("\\uploads\\"); try { if (ServletFileUpload.isMultipartContent(request)) { try { String name = ""; List<FileItem> multiparts; multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { name = new File(item.getName()).getName(); item.write(new File(UPLOAD_DIRECTORY + File.separator + name)); } else if (item.isFormField()) { String fiel = item.getFieldName(); InputStream is = item.getInputStream(); byte[] b = new byte[is.available()]; is.read(b); type = new String(b); } } //File uploaded successfully Connection connect = OracleConnect.getConnect(Dir.Host, Dir.Port, Dir.Service, Dir.UserName, Dir.PassWord); pro = connect.prepareCall("{call STILL_INSERT_TEST(?,?)}"); pro.setInt(1, 2); pro.setString(2, name); pro.executeQuery(); pro.close(); connect.close(); if (name != null) { request.setAttribute("type", type); request.setAttribute("success", "ok"); } } catch (Exception ex) { request.setAttribute("message", "File Upload Failed due to " + ex); } } else { request.setAttribute("message", "Sorry this Servlet only handles file upload request"); } request.getRequestDispatcher("/SearchEngine.jsp").forward(request, response); } finally { out.close(); } }
From source file:com.mobilewallet.common.dao.ForgotPasswordDAO.java
public int checkResetLink(String uuid, String userId, String ip) { Connection connection = null; CallableStatement cstmt = null; int rvalue = -1; try {/* w w w. j av a2s . c om*/ connection = dataSource.getConnection(); cstmt = connection.prepareCall("{call wp_check_reset_link(?,?,?,?)}"); cstmt.setString(1, userId); cstmt.setString(2, uuid); cstmt.setString(3, ip); cstmt.registerOutParameter(4, java.sql.Types.INTEGER); cstmt.execute(); rvalue = cstmt.getInt(4); log.info("Rvalue Check ResetLink : " + rvalue); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return rvalue; }
From source file:com.mobilewallet.common.dao.ForgotPasswordDAO.java
public int resetPassword(String uuid, String userId, String password, String ip) { Connection connection = null; CallableStatement cstmt = null; int rvalue = -1; try {//from w w w. j a va2 s. c o m connection = dataSource.getConnection(); cstmt = connection.prepareCall("{call wp_reset_pwd(?,?,?,?,?)}"); cstmt.setString(1, userId); cstmt.setString(2, uuid); cstmt.setString(3, password); cstmt.setString(4, ip); cstmt.registerOutParameter(5, java.sql.Types.INTEGER); cstmt.execute(); rvalue = cstmt.getInt(5); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return rvalue; }
From source file:com.app.uploads.ImageUploads.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www . ja v a 2 s.co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String[] Fielname = new String[2]; CallableStatement pro; int i = 0; String UPLOAD_DIRECTORY = getServletContext().getRealPath("\\uploads\\"); try { if (ServletFileUpload.isMultipartContent(request)) { try { String name = ""; List<FileItem> multiparts; multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { name = new File(item.getName()).getName(); item.write(new File(UPLOAD_DIRECTORY + File.separator + name)); } else if (item.isFormField()) { String fiel = item.getFieldName(); InputStream is = item.getInputStream(); byte[] b = new byte[is.available()]; is.read(b); if (i == 0) { Fielname[0] = new String(b); } else { Fielname[1] = new String(b); } i++; } } //File uploaded successfully Connection connect = OracleConnect.getConnect(Dir.Host, Dir.Port, Dir.Service, Dir.UserName, Dir.PassWord); pro = connect.prepareCall("{call STILL_INSERT(?,?,?)}"); pro.setString(1, name); pro.setString(2, Fielname[0]); pro.setString(3, Fielname[1]); pro.executeQuery(); pro.close(); connect.close(); request.setAttribute("message", "File Uploaded Successfully"); request.setAttribute("name", name); } catch (Exception ex) { request.setAttribute("message", "File Upload Failed due to " + ex); } } else { request.setAttribute("message", "Sorry this Servlet only handles file upload request"); } out.print("Description:" + Fielname[0]); out.print("Locator:" + Fielname[1]); String pathReal = getServletContext().getRealPath("\\uploads\\"); request.setAttribute("Description", Fielname[0]); request.setAttribute("Locator", Fielname[1]); request.setAttribute("path", pathReal); request.getRequestDispatcher("/result.jsp").forward(request, response); } finally { out.close(); } }
From source file:com.mobilewallet.common.dao.ReferralIncentiveDAO.java
public String showInvitationStrig(long userId) { Connection connection = null; CallableStatement cstmt = null; String show = null;/*from ww w . j a v a 2s .c om*/ try { connection = dataSource.getConnection(); cstmt = connection.prepareCall("{call wp_show_invitation(?,?)}"); cstmt.setLong(1, userId); cstmt.registerOutParameter(2, java.sql.Types.VARCHAR); cstmt.execute(); show = cstmt.getString(2); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return show; }
From source file:net.solarnetwork.node.dao.jdbc.derby.DerbyOnlineSyncJob.java
private void executeProcedure(final String procedure) { jdbcOperations.execute(new CallableStatementCreator() { public CallableStatement createCallableStatement(Connection con) throws SQLException { log.trace("Calling {} procedure", procedure); return con.prepareCall(procedure); }/*from www .j a va 2s . c o m*/ }, new CallableStatementCallback<Object>() { public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException { cs.execute(); return null; } }); }
From source file:com.mobilewallet.common.dao.LoginDAO.java
public String getUserPassword(String email, String ip) { Connection connection = null; CallableStatement cstmt = null; String password = null;//from www. ja va 2 s . c o m try { connection = dataSource.getConnection(); cstmt = connection.prepareCall("{call fp_forgot_password(?,?,?)}"); cstmt.setString(1, email); cstmt.setString(2, ip); cstmt.registerOutParameter(3, java.sql.Types.VARCHAR); cstmt.execute(); password = cstmt.getString(3); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return password; }
From source file:com.mobilewallet.common.dao.ReferralIncentiveDAO.java
public Object[] addReferralIncetive(long userId, String refCode, String imei, String ip) { int added = 0; Connection connection = null; CallableStatement cstmt = null; String gcmId = null;/*w w w.j a va 2 s . c o m*/ Object[] obj = null; try { connection = dataSource.getConnection(); cstmt = connection.prepareCall("{call ADD_REFERRAL_CREDIT(?,?,?,?,?,?,?)}"); cstmt.setLong(1, userId); cstmt.setString(2, refCode); cstmt.setString(3, imei); cstmt.setString(4, ip); cstmt.registerOutParameter(5, java.sql.Types.INTEGER); cstmt.registerOutParameter(6, java.sql.Types.VARCHAR); cstmt.registerOutParameter(7, java.sql.Types.VARCHAR); cstmt.execute(); added = cstmt.getInt(5); gcmId = cstmt.getString(6); obj = new Object[3]; obj[0] = added; obj[1] = gcmId; obj[2] = cstmt.getString(7); } catch (Exception ex) { ex.printStackTrace(); log.error("Error in add referral incentive dao : " + ex.getMessage() + ", USER ID " + userId + ", refCode : " + refCode + ", imei : " + imei + ", IP : " + ip); } finally { try { if (cstmt != null) { cstmt.close(); } } catch (Exception ex) { } try { if (connection != null) { connection.close(); } } catch (Exception ex) { } } return obj; }
From source file:com.wabacus.system.component.application.report.configbean.editablereport.StoreProcedureActionBean.java
public void updateData(ReportRequest rrequest, ReportBean rbean, Map<String, String> mRowData, Map<String, String> mParamValues) throws SQLException { AbsDatabaseType dbtype = rrequest.getDbType(this.ownerGroupBean.getDatasource()); Connection conn = rrequest.getConnection(this.ownerGroupBean.getDatasource()); CallableStatement cstmt = null; try {//from w w w . j a v a 2 s . c o m if (Config.show_sql) log.info("Execute sql:" + sql); cstmt = conn.prepareCall(sql); if (lstParams != null && lstParams.size() > 0) { int idx = 1; IDataType varcharTypeObj = Config.getInstance().getDataTypeByClass(VarcharType.class); EditableReportParamBean paramBeanTmp; for (Object paramObjTmp : this.lstParams) { if (paramObjTmp instanceof EditableReportParamBean) { paramBeanTmp = (EditableReportParamBean) paramObjTmp; paramBeanTmp.getDataTypeObj().setPreparedStatementValue(idx++, getParamValue(mRowData, mParamValues, rbean, rrequest, paramBeanTmp), cstmt, dbtype); } else { varcharTypeObj.setPreparedStatementValue(idx++, paramObjTmp == null ? "" : String.valueOf(paramObjTmp), cstmt, dbtype); } } } int outputindex = -1; if (this.returnValueParamname != null && !this.returnValueParamname.trim().equals("")) { outputindex = this.lstParams == null ? 1 : this.lstParams.size() + 1; cstmt.registerOutParameter(outputindex, java.sql.Types.VARCHAR); } cstmt.execute(); if (outputindex > 0) { String rtnVal = cstmt.getString(outputindex); storeReturnValue(rrequest, mParamValues, rtnVal); } } finally { WabacusAssistant.getInstance().release(null, cstmt); } }