@WdprMethodLog private static void loadCustomerDetails(Customer customer) throws ClassNotFoundException, IOException, SQLException, Exception { Connection conn = null; PreparedStatement statement = null; ResultSet rs = null; try { logging.debug(" Start loadCustomer"); DBConnectionFactory dbFactory = DBConnectionFactory.getInstance(); conn = dbFactory.getConnection(); long queryStartTime = System.nanoTime(); queryStartTime = System.nanoTime(); String sql = buildInsertQuery(customer); statement = conn.prepareStatement(sql); statement = populateValues(customer, statement); rs = statement.executeQuery(); long queryEndTime = System.nanoTime(); logging.info( "Total_time_PS_loadCustomer : taken to execute loadCustomer query:=" + TimeUnit.MILLISECONDS.convert( (queryEndTime - queryStartTime), TimeUnit.NANOSECONDS)); logging.debug(" End time of loadCustomer Query : "); } catch (Exception ex) { logging.error(ex.getLocalizedMessage()); throw ex; } finally { if (rs != null) rs.close(); if (statement != null) statement.close(); if (conn != null) conn.close(); } }
public static void main(String[] args) { AssociationDataDumpDao dao = new AssociationDataDumpDao(); try { System.out.println("Enter offset max-record db-password"); if (args.length < 2) { System.out.println("Not entered all parameters...."); return; } dao.offset = Integer.parseInt(args[0]); dao.MAX_RECORD = Integer.parseInt(args[1]); dao.LOG_FILE = dao.LOG_FILE + dao.offset + ".log"; dao.errorWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dao.LOG_FILE), "UTF8")); if (args.length > 2) { dao.password = args[2]; } Connection conn = DBConnectionFactory.getInstance(dao.password).getConnection(); dao.pstmt = conn.prepareStatement("select pageId from Page LIMIT " + dao.LIMIT + " offset ?"); PreparedStatement linkOverlapStmt = conn.prepareStatement(dao.SELECT_ASS_OVERLAP_QUERY); PreparedStatement linkCatOverlapStmt = conn.prepareStatement(dao.ASS_PARENT_OVERLAP_QUERY); PreparedStatement selectLinkCatOverlapStmt = conn.prepareStatement(dao.SELECT_ASS_PARENT_OVERLAP); PreparedStatement selectOutlinksStmt = conn.prepareStatement(dao.SELECT_OUTLINKS); PreparedStatement selectOutlinkOverlapStmt = conn.prepareStatement(dao.SELECT_IS_EXISTS_PAGE_OVERLAP); int pageId = 0; int outLinkId = 0; while (dao.offset + dao.LIMIT <= dao.MAX_RECORD) { final List<Integer> pageIdList = dao.getPageIdList(dao.offset); for (int i = 0, size = pageIdList.size(); i < size; i++) { pageId = pageIdList.get(i); selectOutlinksStmt.setInt(1, pageId); ResultSet result = selectOutlinksStmt.executeQuery(); List<Integer> outLinks = new ArrayList<Integer>(); while (result.next()) { outLinks.add(result.getInt("outLinks")); } result.close(); for (int j = 0, outSize = outLinks.size(); j < outSize; j++) { outLinkId = outLinks.get(j); selectOutlinkOverlapStmt.setInt(1, pageId); selectOutlinkOverlapStmt.setInt(2, outLinkId); selectOutlinkOverlapStmt.setInt(3, outLinkId); selectOutlinkOverlapStmt.setInt(4, pageId); result = selectOutlinkOverlapStmt.executeQuery(); if (!(result != null && result.next())) { linkOverlapStmt.setInt(1, pageId); linkOverlapStmt.setInt(2, outLinkId); linkOverlapStmt.addBatch(); try { String[] catOverlap = dao.getParentOverlap( selectLinkCatOverlapStmt, dao.errorWriter, pageId, outLinkId); if (catOverlap != null) { linkCatOverlapStmt.setInt(1, pageId); linkCatOverlapStmt.setInt(2, outLinkId); linkCatOverlapStmt.setString(3, catOverlap[0]); linkCatOverlapStmt.setString(4, catOverlap[1]); linkCatOverlapStmt.addBatch(); } } catch (Exception e) { try { dao.errorWriter.write( "getting overlap falied" + pageId + " " + outLinkId + e.getMessage() + " " + e.getCause() + "\n"); } catch (Exception exp) { exp.printStackTrace(); } } } if (result != null) result.close(); } System.out.println("done .." + (i + dao.offset)); } try { linkCatOverlapStmt.executeBatch(); } catch (Exception e) { try { dao.errorWriter.write( "linkCatOverlapStmt falied" + pageId + " " + outLinkId + e.getMessage() + " " + e.getCause() + "\n"); } catch (Exception exp) { exp.printStackTrace(); } } try { linkOverlapStmt.executeBatch(); } catch (Exception e) { try { dao.errorWriter.write( "linkOverlapStmt falied" + pageId + " " + outLinkId + e.getMessage() + " " + e.getCause() + "\n"); } catch (Exception exp) { exp.printStackTrace(); } } dao.offset = dao.offset + dao.LIMIT; try { linkOverlapStmt.close(); linkCatOverlapStmt.close(); selectLinkCatOverlapStmt.close(); selectOutlinksStmt.close(); selectOutlinkOverlapStmt.close(); conn.close(); conn = DBConnectionFactory.getInstance(dao.password).getConnection(); dao.pstmt = conn.prepareStatement("select pageId from Page LIMIT " + dao.LIMIT + " offset ?"); linkOverlapStmt = conn.prepareStatement(dao.SELECT_ASS_OVERLAP_QUERY); linkCatOverlapStmt = conn.prepareStatement(dao.ASS_PARENT_OVERLAP_QUERY); selectLinkCatOverlapStmt = conn.prepareStatement(dao.SELECT_ASS_PARENT_OVERLAP); selectOutlinksStmt = conn.prepareStatement(dao.SELECT_OUTLINKS); selectOutlinkOverlapStmt = conn.prepareStatement(dao.SELECT_IS_EXISTS_PAGE_OVERLAP); } catch (Exception e) { try { dao.errorWriter.write( "connection closed falied after" + dao.offset + e.getMessage() + " " + e.getCause() + "\n"); } catch (Exception exp) { exp.printStackTrace(); } } } } catch (Exception e) { e.printStackTrace(); try { dao.errorWriter.write("initalization falied" + e.getMessage() + " " + e.getCause() + "\n"); } catch (Exception exp) { exp.printStackTrace(); } } try { dao.errorWriter.flush(); dao.errorWriter.close(); } catch (Exception e) { e.printStackTrace(); } }