static void task1() throws FileNotFoundException, IOException, SQLException { // Read Input System.out.println("Task1 Started..."); BufferedReader br = new BufferedReader(new FileReader(inputFile)); br.readLine(); String task1Input = br.readLine(); br.close(); double supportPercent = Double.parseDouble(task1Input.split(":")[1].split("=")[1].split("%")[0].trim()); if (supportPercent >= 0) { System.out.println("Task1 Support Percent :" + supportPercent); // Prepare query String task1Sql = "select temp.iname,(temp.counttrans/temp2.uniquetrans)*100 as percent" + " from (select i.itemname iname,count(t.transid) counttrans from trans t, items i" + " where i.itemid = t.itemid group by i.itemname having count(t.transid)>=(select count(distinct transid)*" + supportPercent / 100 + " from trans)" + ") temp , (select count(distinct transid) uniquetrans from trans) temp2 order by percent"; PreparedStatement selTask1 = con.prepareStatement(task1Sql); ResultSet rsTask1 = selTask1.executeQuery(); BufferedWriter bw = new BufferedWriter(new FileWriter("system.out.1")); while (rsTask1.next()) { bw.write("{" + rsTask1.getString(1) + "}, s=" + rsTask1.getDouble(2) + "%"); bw.newLine(); } rsTask1.close(); bw.close(); System.out.println("Task1 Completed...\n"); } else System.out.println("Support percent should be a positive number"); }
/** * Method to build a vector from a ResultSet * * @param <code>ResultSet rsResult</code> the result from a query * @return Vector of objects from the ResultSet * @exception Throws Exception on error */ protected Vector buildObjectVector(ResultSet rsResult) throws Exception { // vector for return data Vector vReturn = null; try { // init the vector vReturn = new Vector(super.VECT_INIT_SIZE, super.VECT_GROW_SIZE); // loop through the entire result set while (rsResult.next()) { // create a new one StageUsacForm objTmp = new StageUsacForm(); // set the attributes // ADDING A NEW FIELD "ROWID" objTmp.ROWID = rsResult.getString("ROWID"); objTmp.HDR_SPIN = rsResult.getLong("HDR_SPIN"); objTmp.SPIN_NM = rsResult.getString("SPIN_NM"); objTmp.RCPNT_EMAIL = rsResult.getString("RCPNT_EMAIL"); objTmp.USAC_EMAIL = rsResult.getString("USAC_EMAIL"); objTmp.RFRNC_NMBR = rsResult.getString("RFRNC_NMBR"); objTmp.RCRD_CNT = rsResult.getLong("RCRD_CNT"); objTmp.TOT_PAYMENT = rsResult.getDouble("TOT_PAYMENT"); objTmp.USAC_PRCS_DAT = rsResult.getDate("USAC_PRCS_DAT"); objTmp.RTRCT_FLAG = rsResult.getString("RTRCT_FLAG"); objTmp.DTL_SPIN = rsResult.getLong("DTL_SPIN"); objTmp.FRN = rsResult.getLong("FRN"); objTmp.SDC_INV_NO = rsResult.getString("SDC_INV_NO"); objTmp.AMT_PAID = rsResult.getDouble("AMT_PAID"); objTmp.DSBRSMNT_TXT = rsResult.getString("DSBRSMNT_TXT"); objTmp.EMAIL_DATE = rsResult.getDate("EMAIL_DATE"); objTmp.FILENAME = rsResult.getString("FILENAME"); objTmp.PROCESS_DATE = rsResult.getDate("PROCESS_DATE"); objTmp.STATUS = rsResult.getLong("STATUS"); // add it to the vector vReturn.addElement(objTmp); } return vReturn; } catch (Exception e) { throw new Exception("BuildObjectVector()\n" + e.getMessage()); } }
private DecathlonEvents parseDecathlonEvents(ResultSet athleteSet) throws SQLException { String[] eventColumns = { "race_100m", "long_jump", "shot_put", "high_jump", "race_400m", "hurdles_110m", "discus_throw", "pole_vault", "javelin_throw", "race_1500m" }; double[] results = new double[eventColumns.length]; for (int i = 0; i < eventColumns.length; i++) { results[i] = athleteSet.getDouble(eventColumns[i]); } return new DecathlonEvents(results); }
public UserManager() { registeredUsers = new Hashtable<String, UserID>(HTABLE_INIT_CAP, HTABLE_LOAD_FACT); DBConnect connection = new DBConnect(); connection.setResultSet(); ResultSet data = connection.getData(); try { while (data.next()) { String username = data.getString("Username"); String password = data.getString("Password"); String name = data.getString("Name"); String[] enumFieldString = new String[Attributes.NUM_ENUM_FIELDS]; int start = UserID.NUM_UID_ENTRIES + 1; int i = start; int j = 0; while (i < start + Attributes.NUM_ENUM_FIELDS) { enumFieldString[j] = data.getString(i); i++; j++; } int age = data.getInt("Age"); int weight = data.getInt("Weight"); double height = data.getDouble("Height"); Attributes attributes = new Attributes(enumFieldString, age, weight, height); UserID user = new UserID(username, password, name, attributes); registeredUsers.put(username, user); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } connection.closeConnection(); }
public synchronized void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { HttpSession dbSession = request.getSession(); JspFactory _jspxFactory = JspFactory.getDefaultFactory(); PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true); ServletContext dbApplication = dbSession.getServletContext(); try { PrintWriter out = response.getWriter(); nseer_db_backup1 stock_db = new nseer_db_backup1(dbApplication); nseer_db_backup1 crm_db = new nseer_db_backup1(dbApplication); if (stock_db.conn((String) dbSession.getAttribute("unit_db_name")) && crm_db.conn((String) dbSession.getAttribute("unit_db_name"))) { FileKind FileKind = new FileKind(); ValidataNumber validata = new ValidataNumber(); ValidataRecord vr = new ValidataRecord(); counter count = new counter(dbApplication); ValidataTag vt = new ValidataTag(); String register_ID = (String) dbSession.getAttribute("human_IDD"); String config_id = request.getParameter("config_id"); String pay_ID = request.getParameter("pay_ID"); String product_amount = request.getParameter("product_amount"); int num = Integer.parseInt(product_amount); String payer_name = request.getParameter("payer_name"); String payer_ID = request.getParameter("payer_ID"); String reason = request.getParameter("reason"); String not_return_tag = request.getParameter("not_return_tag"); String register = request.getParameter("register"); String register_time = request.getParameter("register_time"); String demand_return_time = request.getParameter("demand_return_time"); String sales_name = request.getParameter("sales_name"); String sales_ID = request.getParameter("sales_ID"); String bodyc = new String(request.getParameter("remark").getBytes("UTF-8"), "UTF-8"); String remark = exchange.toHtml(bodyc); String time = ""; java.util.Date now = new java.util.Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); time = formatter.format(now); String[] product_IDn = request.getParameterValues("product_ID"); String[] amountn = request.getParameterValues("amount"); if (num == 0 && product_IDn.length == 1) { response.sendRedirect("draft/crm/credit_ok_a.jsp?pay_ID=" + pay_ID); } else { int p = 0; for (int i = 1; i <= num; i++) { String tem_amount = "amount" + i; String amount = request.getParameter(tem_amount); if (amount.equals("")) amount = "0"; if (!validata.validata(amount)) { p++; } } int n = 0; String product_ID_group = ""; for (int j = 1; j < product_IDn.length; j++) { product_ID_group += product_IDn[j] + ","; if (amountn[j].equals("")) amountn[j] = "0"; if (!validata.validata(amountn[j])) { p++; } } for (int i = 1; i <= num; i++) { String tem_product_ID = "product_ID" + i; String product_ID = request.getParameter(tem_product_ID); if (product_ID_group.indexOf(product_ID) != -1) n++; } if (vt.validata( (String) dbSession.getAttribute("unit_db_name"), "stock_apply_pay", "pay_ID", pay_ID, "check_tag") .equals("9") || vt.validata( (String) dbSession.getAttribute("unit_db_name"), "stock_apply_pay", "pay_ID", pay_ID, "check_tag") .equals("5")) { if (p == 0) { try { if (n == 0) { boolean flag = false; List rsList = GetWorkflow.getList(crm_db, "crm_config_workflow", "05"); String[] elem = new String[3]; if (rsList.size() == 0) { flag = true; } String sqll = ""; String[] aaa1 = FileKind.getKind( (String) dbSession.getAttribute("unit_db_name"), "crm_file", "customer_ID", payer_ID); String stock_pay_ID = NseerId.getId("stock/pay", (String) dbSession.getAttribute("unit_db_name")); double demand_amount = 0.0d; double list_price_sum = 0.0d; double cost_price_sum = 0.0d; for (int i = 1; i <= num; i++) { String tem_product_name = "product_name" + i; String tem_product_ID = "product_ID" + i; String tem_available_amount = "available_amount" + i; String tem_amount = "amount" + i; String tem_list_price = "list_price" + i; String tem_cost_price = "cost_price" + i; String tem_type = "type" + i; String tem_amount_unit = "amount_unit" + i; String product_name = request.getParameter(tem_product_name); String product_ID = request.getParameter(tem_product_ID); String available_amount = request.getParameter(tem_available_amount); String amount = request.getParameter(tem_amount); if (amount.equals("")) amount = "0"; String list_price2 = request.getParameter(tem_list_price); String cost_price = request.getParameter(tem_cost_price); String type = request.getParameter(tem_type); StringTokenizer tokenTO3 = new StringTokenizer(list_price2, ","); String list_price = ""; while (tokenTO3.hasMoreTokens()) { String list_price1 = tokenTO3.nextToken(); list_price += list_price1; } String amount_unit = request.getParameter(tem_amount_unit); double list_price_subtotal = Double.parseDouble(list_price) * Double.parseDouble(amount); list_price_sum += list_price_subtotal; double cost_price_subtotal = Double.parseDouble(cost_price) * Double.parseDouble(amount); cost_price_sum += cost_price_subtotal; demand_amount += Double.parseDouble(amount); String sql1 = "update stock_apply_pay_details set amount='" + amount + "',list_price='" + list_price + "',list_price_subtotal='" + list_price_subtotal + "',cost_price='" + cost_price + "',subtotal='" + cost_price_subtotal + "' where pay_ID='" + pay_ID + "' and details_number='" + i + "'"; stock_db.executeUpdate(sql1); if (flag) { if (type.equals("物料") || type.equals("外购商品")) { String sql2 = "insert into stock_pay_details(pay_ID,details_number,product_ID,product_name,type,list_price,list_price_subtotal,cost_price,subtotal,amount,unpay_amount,apply_manufacture_amount,apply_purchase_amount) values('" + stock_pay_ID + "','" + i + "','" + product_ID + "','" + product_name + "','" + type + "','" + list_price + "','" + list_price_subtotal + "','" + cost_price + "','" + cost_price_subtotal + "','" + amount + "','" + amount + "','0','" + amount + "')"; stock_db.executeUpdate(sql2); } else if (type.equals("商品") || type.equals("部件") || type.equals("委外部件")) { String sql2 = "insert into stock_pay_details(pay_ID,details_number,product_ID,product_name,type,list_price,list_price_subtotal,cost_price,subtotal,amount,unpay_amount,apply_manufacture_amount,apply_purchase_amount) values('" + stock_pay_ID + "','" + i + "','" + product_ID + "','" + product_name + "','" + type + "','" + list_price + "','" + list_price_subtotal + "','" + cost_price + "','" + cost_price_subtotal + "','" + amount + "','" + amount + "','" + amount + "','0')"; stock_db.executeUpdate(sql2); } String sql97 = "select * from crm_salecredit_balance_details where crediter_ID='" + payer_ID + "' and product_ID='" + product_ID + "'"; ResultSet rs97 = crm_db.executeQuery(sql97); if (rs97.next()) { double balance_amount = rs97.getDouble("amount") + Double.parseDouble(amount); double balance_cost_price_subtotal = rs97.getDouble("subtotal") + cost_price_subtotal; double balance_list_price_subtotal = rs97.getDouble("list_price_subtotal") + list_price_subtotal; String sql96 = "update crm_salecredit_balance_details set amount='" + balance_amount + "',check_tag='1',subtotal='" + balance_cost_price_subtotal + "',list_price_subtotal='" + balance_list_price_subtotal + "' where crediter_ID='" + payer_ID + "' and product_ID='" + product_ID + "'"; crm_db.executeUpdate(sql96); } else { String[] aaa = FileKind.getKind( (String) dbSession.getAttribute("unit_db_name"), "design_file", "product_ID", product_ID); String sql95 = "insert into crm_salecredit_balance_details(chain_ID,chain_name,crediter_chain_ID,crediter_chain_name,product_ID,product_name,list_price,list_price_subtotal,cost_price,subtotal,amount,crediter_ID,crediter_name) values('" + aaa[0] + "','" + aaa[1] + "','" + aaa1[0] + "','" + aaa1[1] + "','" + product_ID + "','" + product_name + "','" + list_price + "','" + list_price_subtotal + "','" + cost_price + "','" + cost_price_subtotal + "','" + amount + "','" + payer_ID + "','" + payer_name + "')"; crm_db.executeUpdate(sql95); } } } String[] cost_pricen = request.getParameterValues("cost_price"); String[] list_pricen = request.getParameterValues("list_price"); String[] product_namen = request.getParameterValues("product_name"); String[] product_describen = request.getParameterValues("product_describe"); String[] amount_unitn = request.getParameterValues("amount_unit"); String[] typen = request.getParameterValues("type"); for (int i = 1; i < product_IDn.length; i++) { StringTokenizer tokenTO3 = new StringTokenizer(list_pricen[i], ","); String list_price = ""; while (tokenTO3.hasMoreTokens()) { String list_price1 = tokenTO3.nextToken(); list_price += list_price1; } if (!amountn[i].equals("") && Double.parseDouble(amountn[i]) != 0) { double list_price_subtotal = Double.parseDouble(list_price) * Double.parseDouble(amountn[i]); list_price_sum += list_price_subtotal; double subtotal = Double.parseDouble(cost_pricen[i]) * Double.parseDouble(amountn[i]); cost_price_sum += subtotal; demand_amount += Double.parseDouble(amountn[i]); num++; String sql1 = "insert into stock_apply_pay_details(payer_chain_ID,payer_chain_name,sales_ID,sales_name,payer_ID,payer_name,payer_type,pay_ID,details_number,product_ID,product_name,product_describe,amount,amount_unit,list_price,list_price_subtotal,cost_price,subtotal,type) values ('" + aaa1[0] + "','" + aaa1[1] + "','" + sales_ID + "','" + sales_name + "','" + payer_ID + "','" + payer_name + "','销售赊货','" + pay_ID + "','" + num + "','" + product_IDn[i] + "','" + product_namen[i] + "','" + product_describen[i] + "','" + amountn[i] + "','" + amount_unitn[i] + "','" + list_price + "','" + list_price_subtotal + "','" + cost_pricen[i] + "','" + subtotal + "','" + typen[i] + "')"; stock_db.executeUpdate(sql1); // ********************** if (rsList.size() == 0) { if (typen[i].equals("物料") || typen[i].equals("外购商品")) { String sql2 = "insert into stock_pay_details(pay_ID,details_number,product_ID,product_name,type,list_price,list_price_subtotal,cost_price,subtotal,amount,unpay_amount,apply_manufacture_amount,apply_purchase_amount) values('" + stock_pay_ID + "','" + num + "','" + product_IDn[i] + "','" + product_namen[i] + "','" + typen[i] + "','" + list_price + "','" + list_price_subtotal + "','" + cost_pricen[i] + "','" + subtotal + "','" + amountn[i] + "','" + amountn[i] + "','0','" + amountn[i] + "')"; stock_db.executeUpdate(sql2); } else if (typen[i].equals("商品") || typen[i].equals("部件") || typen[i].equals("委外部件")) { String sql2 = "insert into stock_pay_details(pay_ID,details_number,product_ID,product_name,type,list_price,list_price_subtotal,cost_price,subtotal,amount,unpay_amount,apply_manufacture_amount,apply_purchase_amount) values('" + stock_pay_ID + "','" + num + "','" + product_IDn[i] + "','" + product_namen[i] + "','" + typen[i] + "','" + list_price + "','" + list_price_subtotal + "','" + cost_pricen[i] + "','" + subtotal + "','" + amountn[i] + "','" + amountn[i] + "','" + amountn[i] + "','0')"; stock_db.executeUpdate(sql2); } String sql97 = "select * from crm_salecredit_balance_details where crediter_ID='" + payer_ID + "' and product_ID='" + product_IDn[i] + "'"; ResultSet rs97 = crm_db.executeQuery(sql97); if (rs97.next()) { double balance_amount = rs97.getDouble("amount") + Double.parseDouble(amountn[i]); double balance_cost_price_subtotal = rs97.getDouble("subtotal") + subtotal; double balance_list_price_subtotal = rs97.getDouble("list_price_subtotal") + list_price_subtotal; String sql96 = "update crm_salecredit_balance_details set amount='" + balance_amount + "',check_tag='1',subtotal='" + balance_cost_price_subtotal + "',list_price_subtotal='" + balance_list_price_subtotal + "' where crediter_ID='" + payer_ID + "' and product_ID='" + product_IDn[i] + "'"; crm_db.executeUpdate(sql96); } else { String[] aaa = FileKind.getKind( (String) dbSession.getAttribute("unit_db_name"), "design_file", "product_ID", product_IDn[i]); String sql95 = "insert into crm_salecredit_balance_details(chain_ID,chain_name,crediter_chain_ID,crediter_chain_name,product_ID,product_name,list_price,list_price_subtotal,cost_price,subtotal,amount,crediter_ID,crediter_name) values('" + aaa[0] + "','" + aaa[1] + "','" + aaa1[0] + "','" + aaa1[1] + "','" + product_IDn[i] + "','" + product_namen[i] + "','" + list_price + "','" + list_price_subtotal + "','" + cost_pricen[i] + "','" + subtotal + "','" + amountn[i] + "','" + payer_ID + "','" + payer_name + "')"; crm_db.executeUpdate(sql95); } } // *************************** } } String sql = "update stock_apply_pay set reason='" + reason + "',register='" + register + "',register_time='" + register_time + "',demand_return_time='" + demand_return_time + "',register_time='" + register_time + "',register='" + register + "',remark='" + remark + "',demand_amount='" + demand_amount + "',list_price_sum='" + list_price_sum + "',cost_price_sum='" + cost_price_sum + "',not_return_tag='" + not_return_tag + "' where pay_ID='" + pay_ID + "'"; stock_db.executeUpdate(sql); if (flag) { sql = "update stock_apply_pay set check_tag='1' where pay_ID='" + pay_ID + "'"; stock_db.executeUpdate(sql); if (!vr.validata( (String) dbSession.getAttribute("unit_db_name"), "stock_pay", "reasonexact", pay_ID)) { String sql4 = "insert into stock_pay(pay_ID,reason,reasonexact,reasonexact_details,demand_amount,list_price_sum,cost_price_sum,register,register_time) values('" + stock_pay_ID + "','" + reason + "','" + pay_ID + "','" + payer_name + "','" + demand_amount + "','" + list_price_sum + "','" + cost_price_sum + "','" + register + "','" + register_time + "')"; stock_db.executeUpdate(sql4); } String sql98 = "select * from crm_file where customer_ID='" + payer_ID + "'"; ResultSet rs98 = crm_db.executeQuery(sql98); if (rs98.next()) { double salecredit_list_price_sum = rs98.getDouble("salecredit_list_price_sum") + list_price_sum; double salecredit_cost_price_sum = rs98.getDouble("salecredit_cost_price_sum") + cost_price_sum; String sql99 = "update crm_file set credit_yes_or_not_tag='1',salecredit_list_price_sum='" + salecredit_list_price_sum + "',salecredit_cost_price_sum='" + salecredit_cost_price_sum + "' where customer_ID='" + payer_ID + "' "; crm_db.executeUpdate(sql99); } } else { sql = "update stock_apply_pay set check_tag='0' where pay_ID='" + pay_ID + "'"; stock_db.executeUpdate(sql); Iterator ite = rsList.iterator(); while (ite.hasNext()) { elem = (String[]) ite.next(); sql = "insert into crm_workflow(config_id,object_ID,describe1,describe2) values ('" + elem[0] + "','" + pay_ID + "','" + elem[1] + "','" + elem[2] + "')"; crm_db.executeUpdate(sql); } } response.sendRedirect("draft/crm/credit_ok.jsp?finished_tag=8"); } else { response.sendRedirect( "draft/crm/credit_ok.jsp?finished_tag=7&pay_ID=" + pay_ID + ""); } } catch (Exception ex) { ex.printStackTrace(); } } else { response.sendRedirect("draft/crm/credit_ok.jsp?finished_tag=6&pay_ID=" + pay_ID + ""); } } else { response.sendRedirect("draft/crm/credit_ok.jsp?finished_tag=9"); } } stock_db.commit(); crm_db.commit(); stock_db.close(); crm_db.close(); } else { response.sendRedirect("error_conn.htm"); } } catch (Exception ex) { ex.printStackTrace(); } }
public void calculate() { int id = 0; double tf = 0, maxtf = 0, nf = 0, n = 0; double tfidf = 0.0; String qry1, qry2, redoc, qry3; PreparedStatement ps1, ps2, ps3; ResultSet rs1, rs2; try { init(); String query = "select distinct(id) from index "; // where weburl='"+we+"'"; PreparedStatement preparedstatement = con.prepareStatement(query); ResultSet rs = preparedstatement.executeQuery(); while (rs.next()) { n++; } // System.out.println("THE TOTAL DOCUMENT== "+n); query = "select distinct(id) from index "; // where weburl='"+we+"'"; preparedstatement = con.prepareStatement(query); rs = preparedstatement.executeQuery(); while (rs.next()) { id = rs.getInt(1); System.out.println(id); qry1 = "select max(totcon) from wordcount where urlid=" + id + ""; ps1 = con.prepareStatement(qry1); rs1 = ps1.executeQuery(); while (rs1.next()) { maxtf = rs1.getDouble(1); } // System.out.println("THE MAximaus "+maxtf); qry1 = "select word,totcon from wordcount where urlid=" + id + ""; ps1 = con.prepareStatement(qry1); rs1 = ps1.executeQuery(); while (rs1.next()) { redoc = rs1.getString(1); tf = rs1.getDouble(2); // System.out.println("TF "+tf); qry2 = "select word from wordcount where word='" + redoc + "'"; ps2 = con.prepareStatement(qry2); rs2 = ps2.executeQuery(); while (rs2.next()) { nf++; } tfidf = (tf / maxtf) * (nf / n); String xx = "" + tfidf; double finl; if (xx.length() > 5) finl = Double.parseDouble(xx.substring(0, 5)); else finl = tfidf; qry3 = "update wordcount set tfidf=" + finl + " where word='" + redoc + "'"; // System.out.println(qry3); ps3 = con.prepareStatement(qry3); ps3.executeUpdate(); System.out.println("THE N=" + n + "MAX=" + maxtf + "THE Tf=" + tf + "THE NF " + nf); System.out.println("THE TFIDF NT===" + finl); nf = 0; } } con.close(); } catch (Exception ex) { System.out.println("Error in verb :" + ex); } }
static void task2() throws FileNotFoundException, IOException, SQLException { System.out.println("Task2 Started..."); BufferedReader br = new BufferedReader(new FileReader(inputFile)); br.readLine(); br.readLine(); String task2Input = br.readLine(); br.close(); double supportPercent = Double.parseDouble(task2Input.split(":")[1].split("=")[1].split("%")[0].trim()); if (supportPercent >= 0) { System.out.println("Task2 Support percent:" + supportPercent); try { PreparedStatement dropView = con.prepareStatement("drop materialized view trans1"); dropView.executeUpdate(); } catch (SQLException e) { } // Creating materilalized view to filter out transactions as per apriori rule String sqlTransView = "create materialized view trans1(transid,itemid) as select * from trans where itemid in" + " (select itemid from trans group by itemid having count(*)>=(select count(distinct(transid))*" + supportPercent / 100 + " from trans))"; PreparedStatement createView = con.prepareStatement(sqlTransView); createView.executeUpdate(); createView.close(); // Using SQL from task1 to retrieve item sets of size 1. String task1Sql = "select temp.iname,(temp.counttrans/temp2.uniquetrans)*100 as percent" + " from (select i.itemname iname,count(t.transid) counttrans from trans t, items i" + " where i.itemid = t.itemid group by i.itemname having count(t.transid)>=(select count(distinct transid)*" + supportPercent / 100 + " from trans)" + ") temp , (select count(distinct transid) uniquetrans from trans) temp2 order by percent"; PreparedStatement selTask1 = con.prepareStatement(task1Sql); ResultSet rsTask1 = selTask1.executeQuery(); BufferedWriter bw = new BufferedWriter(new FileWriter("system.out.2")); while (rsTask1.next()) { bw.write("{" + rsTask1.getString(1) + "}, s=" + rsTask1.getDouble(2) + "%"); bw.newLine(); } rsTask1.close(); selTask1.close(); String task2Sql = "select temp.iname1,temp.iname2,(temp.counttrans/temp2.uniquetrans)*100 as percent" + " from(select t1.itemid,t2.itemid,i1.itemname iname1,i2.itemname iname2,count(*) counttrans" + " from trans1 t1,trans1 t2,items i1,items i2 where t1.transid = t2.transid and t1.itemid = i1.itemid" + " and t2.itemid = i2.itemid and t1.itemid < t2.itemid group by t1.itemid,t2.itemid,i1.itemname,i2.itemname" + " having count(*)>=(select count(distinct transid)*" + supportPercent / 100 + " from trans)) temp , (select count(distinct transid) uniquetrans from trans) temp2 order by percent"; PreparedStatement selTask2 = con.prepareStatement(task2Sql); ResultSet rsTask2 = selTask2.executeQuery(); while (rsTask2.next()) { bw.write( "{" + rsTask2.getString(1) + ", " + rsTask2.getString(2) + "}, s=" + rsTask2.getDouble(3) + "%"); bw.newLine(); } rsTask2.close(); selTask2.close(); bw.close(); System.out.println("Task2 Completed...\n"); } else System.out.println("Support percent should be a positive number"); }
static void task4() throws FileNotFoundException, IOException, InterruptedException, SQLException { System.out.println("Task4 Started..."); BufferedReader br = new BufferedReader(new FileReader(inputFile)); br.readLine(); br.readLine(); br.readLine(); br.readLine(); String task4Input = br.readLine(); br.close(); double supportPercent = Double.parseDouble( task4Input.split(":")[1].split(",")[0].split("=")[1].split("%")[0].trim()); double confidence = Double.parseDouble( task4Input.split(":")[1].split(",")[1].split("=")[1].split("%")[0].trim()); int size = Integer.parseInt(task4Input.split(":")[1].split(",")[2].split("=")[1].trim()); if (supportPercent >= 0 && size >= 2 && confidence >= 0) { System.out.println("Task4 Confidence Percent: " + confidence); System.out.println("Task4 Support Percent: " + supportPercent); System.out.println("Task4 Size : " + size); BufferedWriter bw = new BufferedWriter(new FileWriter("system.out.4")); for (int i = 2; i <= size; i++) { CallableStatement cstmt = con.prepareCall("{CALL GenerateAR(?,?,?)}"); cstmt.setDouble(1, confidence / 100); cstmt.setInt(2, i); cstmt.setDouble(3, supportPercent / 100); cstmt.executeQuery(); String sqlTask4 = "select * from artable order by ruleid,confidence"; PreparedStatement selTask4 = con.prepareStatement(sqlTask4); ResultSet rsTask4 = selTask4.executeQuery(sqlTask4); String leftSet = ""; String rightSet = ""; Boolean resultSetExhausted = false; String itemName; String isLeft; Double support; Double conf; if (rsTask4.next()) { while (true && !resultSetExhausted) { leftSet = "{"; rightSet = "{"; for (int j = 0; j < i; j++) { itemName = rsTask4.getString(3); isLeft = rsTask4.getString(5); // support = rsTask4.getBigDecimal(6); // conf = rsTask4.getBigDecimal(4); if (j == 0) { if (isLeft.equals("Y")) leftSet = leftSet + itemName; else rightSet = rightSet + itemName; if (!rsTask4.next()) { resultSetExhausted = true; break; } } if (j == i - 1) { if (isLeft.equals("Y")) { if (leftSet.equals("{")) leftSet = leftSet + itemName; else leftSet = leftSet + "," + itemName; } else { if (rightSet.equals("{")) rightSet = rightSet + itemName; else rightSet = rightSet + ", " + itemName; } leftSet = leftSet + "}"; rightSet = rightSet + "}"; String resultString = "{" + leftSet + " - > " + rightSet + "} s=" + rsTask4.getDouble(6) + "%, c=" + rsTask4.getDouble(4) + "%"; bw.write(resultString); bw.newLine(); leftSet = "{"; rightSet = "{"; if (!rsTask4.next()) { resultSetExhausted = true; break; } } if (j > 0 && j < i - 1) { if (isLeft.equals("Y")) { if (leftSet.equals("{")) leftSet = leftSet + itemName; else leftSet = leftSet + ", " + itemName; } else { if (rightSet.equals("{")) rightSet = rightSet + itemName; else rightSet = rightSet + ", " + itemName; } if (!rsTask4.next()) { resultSetExhausted = true; break; } } } } } } bw.close(); System.out.println("Task4 Completed...\n"); } else System.out.println( "For Task4, supportPercent and confidence should be a positive numbers and size should be greater than or equal to 2"); }
static void task3() throws FileNotFoundException, IOException, InterruptedException, SQLException { System.out.println("Task3 Started.."); BufferedReader br = new BufferedReader(new FileReader(inputFile)); br.readLine(); br.readLine(); br.readLine(); String task3Input = br.readLine(); br.close(); double supportPercent = Double.parseDouble( task3Input.split(":")[1].split(",")[0].split("=")[1].split("%")[0].trim()); int size = Integer.parseInt(task3Input.split(":")[1].split(",")[1].split("=")[1].trim()); if (supportPercent >= 0 && size > 0) { System.out.println("Task3 Size : " + size); System.out.println("Task3 Support Percent: " + supportPercent); BufferedWriter bw = new BufferedWriter(new FileWriter("system.out.3")); for (int i = 1; i <= size; i++) { CallableStatement cstmt = con.prepareCall("{CALL GenerateFI(?,?)}"); cstmt.setInt(1, i); cstmt.setDouble(2, supportPercent / 100); cstmt.executeQuery(); String sqlTask3 = "select i.itemname,f.percent from FISet f ,items i where f.itemid = i.itemid order by f.percent,f.isetid"; // String sqlTask3 = "select i.itemname,f.percent from FISet f ,items i where f.itemid = // i.itemid order by f.isetid"; PreparedStatement selTask3 = con.prepareStatement(sqlTask3); ResultSet rsTask3 = selTask3.executeQuery(sqlTask3); int j = 1; String res = ""; j = 1; while (rsTask3.next()) { if (j == 1) { res += "{"; } res = res + rsTask3.getString(1); if (j == i) { res += "}, s=" + rsTask3.getDouble(2) + "%"; bw.write(res); bw.newLine(); j = 1; res = ""; } else { res += ", "; j++; } } rsTask3.close(); selTask3.close(); } bw.close(); System.out.println("Task3 Completed...\n"); } else { System.out.println( "Support percent should a postive number and size should be a positive integer."); } }