elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  crear dos archivos txt mediante un query al server y sentencia IF
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: crear dos archivos txt mediante un query al server y sentencia IF  (Leído 2,079 veces)
padre_15

Desconectado Desconectado

Mensajes: 5


Ver Perfil
crear dos archivos txt mediante un query al server y sentencia IF
« en: 16 Junio 2016, 20:16 pm »

Buenas Tardes Colegas, tengo el siguiente problema,
necesito que un codigo en java, me traiga informacion esa informacion sacar los terminacion 126 y 113 y meterlos a un archivo txt y los separa por pipes que aqui los ven en el codigo, que estos los guarda en documentos en formato txt,
les comparto mi codigo, en los if crea la sentencia de quienes entran y quienes no, el problema es que nadamas me crea el archivo txt 113 y no el archivo 126 que necesito que cree los dos juntos dividiendolos los que pertenecen a cada uno, los querys me funcionan excelentes, pero no el codigo para extraer archivos, saludos de antemano



Código
  1.  
  2. protected void closing() throws Exception {
  3.        File current;
  4.        ResourceBundle bundle = ResourceBundle.getBundle("");
  5.        Class.forName(bundle.getString("driver"));
  6.        conn = DriverManager.getConnection(bundle.getString("url"), bundle.getString("username"), bundle.getString("password"));
  7.        conn.setAutoCommit(false);
  8.        st = conn.createStatement();
  9.        int flag_tot ;
  10.        ResultSet ot;
  11.        PreparedStatement ps;
  12.        PreparedStatement psu;
  13.        String filter = "";
  14.        filter = " and type_id=20";
  15.  
  16.  
  17.        String qry_visits = "";
  18.        int visit = 0;
  19.        Statement st_aux = conn.createStatement();
  20.        ResultSet rs_aux;
  21.  
  22.  
  23.       String qryot = "select cust_shipping_code as ot,TO_CHAR(current_timestamp,'YYYYMMDDHH24MISS') as fechaHora from consignments c inner join arrivals a on (a.arrival_id=c.arrival_id) "
  24.                + "where a.arrival_date between to_date('" + returnStringDate(this.fromDateChooser.getDate()) + "','yyyy-mm-dd HH24:MI:SS') and to_date('" + returnStringDate(this.toDateChooser.getDate()) + "','yyyy-mm-dd HH24:MI:SS') "
  25.                + "and c.customer_id=" + this.customerTextField.getText() + " and c.product_id in(select product_id from customer_products where category_id=2" + filter + ") and c.cust_shipping_code is not null  group by cust_shipping_code";
  26.  
  27.        String qry = "select cust_shipping_code as pipe1,"
  28.                + "cp.addressee_cust_account as pipe2,"
  29.                + "case cp.customer_id when 100061 then '10' when 491 then '10' when 187 then '10' else substr(c.cust_shipping_code,1,2) end as pipe3,"
  30.                + "case ac.delivery_type when 'C' then '40' when 'R' then '40' when 'D' then '10' end as pipe4,"
  31.                + "case ac.delivery_type when 'C' then '50' when 'R' then rrel.cust_relationship_id when 'D' then rret.cust_reason_id end as pipe5,"
  32.                + "to_char(ac.delivery_date,'dd/mm/yyyy') as  pipe6,"
  33.                + "case ac.delivery_type when 'C' then substr(ac.floor||' PISOS '||ac.color||' '||door.description||' '||CASE WHEN ac.grid_wall is null THEN '' ELSE case when ac.grid_wall='N' then 'SIN REJA' else 'CON REJA' end END||' '||CASE WHEN ac.garage is null THEN '' ELSE case when ac.garage='N' then 'SIN COCHERA' else 'CON COCHERA' end END||' '||meter.description||' '||ac.serial_meter,1,60) "
  34.                + "when 'R' then ac.name when 'D' then '' end as pipe7,"
  35.                + "case ac.delivery_type when 'C' then 'BP' when 'R' then ac.last_name when 'D' then '' end as pipe8,"
  36.                + "case ac.delivery_type when 'C' then '' when 'R' then ac.sec_last_name when 'D' then '' end as pipe9,"
  37.                + "case ac.delivery_type when 'C' then '5' when 'R' then rid.cust_identification_id when 'D' then '' end as pipe10,"
  38.                + "case ac.delivery_type when 'C' then '' when 'R' then (case rid.cust_identification_id when '5' then 'NINGUNO' else  rid.description end) when 'D' then '' end as pipe11,"
  39.                + "case ac.delivery_type when 'C' then '' when 'R' then ac.num_identify when 'D' then '' end as pipe12,"
  40.                + "ac.observations as pipe13,ac.delivery_type as pipe14,"
  41.                + "ac.consignment_id as pipe15,ac.cust_account as pipe16, cp.cnsgnmnt_piece_id as pipe17 "
  42.                + "from consignments c "
  43.                + "inner join cnsgnmnt_pieces cp on (cp.consignment_id=c.consignment_id) "
  44.                + "left join acknowledgment_capture ac on (ac.cust_account=cp.cust_account and ac.consignment_id=cp.consignment_id) "
  45.                + "left join r_return_reason_qp_cust rret on(rret.qp_reason_id=ac.qp_reasons_id and rret.customer_id=c.customer_id and rret.category_id=2) "
  46.                + "left join r_relationship_qp_cust rrel on(rrel.qp_relationship_id=ac.qp_relationship_id and rrel.customer_id=cp.customer_id) "
  47.                + "left join r_identification_qp_cust rid on(rid.qp_identification_id=ac.qp_identify_id and rid.customer_id=cp.customer_id) "
  48.                + "left join catmeter meter on (meter.meter_id=ac.meter_id) "
  49.                + "left join catdoor door on (door.door_id=ac.door_id)  "
  50.                + "where c.cust_shipping_code=? and ac.delivery_type is not null and ac.delivery_type!='I' and ac.progress_ind=0";
  51.  
  52.  
  53.        System.out.println(qry + " busqueda__");
  54.        System.out.println("_____________"+qryot);
  55. //        JOptionPane.showMessageDialog(null, "el query:");
  56. //        System.exit(0);
  57.  
  58.  
  59.  
  60.  
  61.    String qryu = "update acknowledgment_capture ac set ac.progress_ind=2 where ac.consignment_id=? and ac.cust_account=? ";
  62.  
  63.        ps = conn.prepareStatement(qry);
  64.  
  65.        System.out.println("Q:"+qryu);
  66.        psu = conn.prepareStatement(qryu);
  67.  
  68.        int row = 0, deliv = 0, files = 0;
  69.        StringBuilder line = new StringBuilder();
  70.  
  71.  
  72.        String fechaHora, csc, path = "", fileName = "tsis.txt";
  73.        String linea_doc = "";
  74.  
  75.        ot = st.executeQuery(qryot);
  76.        path = "";
  77.        int prueba_alert = 0;
  78.        while (ot.next()) {
  79.  
  80.            csc = ot.getString("ot");
  81.            System.out.println(csc +" el csc");
  82.            fechaHora = ot.getString("fechaHora");
  83.            System.out.println("AQUIIIII");
  84.            String terminacion = csc.substring(csc.length() - 3, csc.length());
  85.  
  86.            if (terminacion.equals("113")) {
  87.  
  88.                flag_tot = 1;
  89.                fileName = "113_" + fechaHora + ".txt";
  90.                gname_113 = fileName;
  91.            } else
  92.                if (terminacion.equals("126")) {
  93.  
  94.                flag_tot = 2;
  95.                fileName = "126_" + fechaHora + ".txt";
  96.                gname_126 = fileName;
  97.                System.out.println("126prueba");
  98.  
  99.            } else {
  100.                flag_tot = 3;
  101.                fileName = "otro_" + fechaHora + ".txt";
  102.                gname_otro = fileName;
  103.  
  104.            }
  105.            HoraFecha = fechaHora;
  106.           ps.setString(1, ot.getString("ot"));
  107.  
  108.  
  109.            if(this.customerTextField.getText().equals("100061"))
  110.            path=csc.substring(csc.length()-5,csc.length())+"";
  111.  
  112.  
  113.            path = "";
  114.            current = new File(savePath + path + fileName);
  115.  
  116.  
  117.            if (current.exists()) {
  118.                current.delete();
  119.            }
  120.  
  121.  
  122.            files++;
  123.            rs = ps.executeQuery();
  124.            System.out.println("OTROOOO");
  125.            while (rs.next()) {
  126.                linea_doc = "";
  127.  
  128.                if ("R".equals(rs.getString("pipe14")) || "C".equals(rs.getString("pipe14"))) {
  129.                    line.append(manageEmpty(rs.getString("pipe1")));
  130.                    line.append("|");
  131.                    line.append(manageEmpty(rs.getString("pipe2")));
  132.                    line.append("|");
  133.                    line.append(manageEmpty(rs.getString("pipe3")));
  134.                    line.append("|");
  135.                    line.append(manageEmpty(rs.getString("pipe4")));
  136.                    line.append("|");
  137.                    line.append(manageEmpty(rs.getString("pipe5")));
  138.                    line.append("|");
  139.                    line.append(manageEmpty(rs.getString("pipe6")));
  140.                    line.append("|");
  141.                    line.append(manageEmpty(rs.getString("pipe7")));
  142.                    line.append("|");
  143.                    line.append(manageEmpty(rs.getString("pipe8")));
  144.                    line.append("|");
  145.                    line.append(manageEmpty(rs.getString("pipe9")));
  146.                    line.append("|");
  147.                    line.append(manageEmpty(rs.getString("pipe10")));
  148.                    line.append("|");
  149.                    line.append(manageEmpty(rs.getString("pipe11")));
  150.                    line.append("|");
  151.                    line.append(manageEmpty(rs.getString("pipe12")));
  152.                    line.append("|");
  153.                    line.append(manageEmpty(rs.getString("pipe13")));
  154.                    line.append("ENTREGA|0");
  155.                    line.append("|");
  156.                    line.append("0");
  157.                    line.append("|");
  158.                    line.append("0");
  159.                    line.append("|0");
  160.  
  161.                } else if ("D".equals(rs.getString("pipe14"))) {
  162.  
  163.                    line.append(manageEmpty(rs.getString("pipe1")));
  164.                    line.append("|");
  165.                    line.append(manageEmpty(rs.getString("pipe2")));
  166.                    line.append("|");
  167.                    line.append(manageEmpty(rs.getString("pipe3")));
  168.                    line.append("|");
  169.  
  170.                    line.append(manageEmpty(rs.getString("pipe4")));
  171.                    line.append("|");
  172.                    line.append(manageEmpty(rs.getString("pipe5")));
  173.                    line.append("|");
  174.  
  175.                    line.append(manageEmpty(rs.getString("pipe6")));
  176.                    line.append("|");
  177.                    line.append(manageEmpty(rs.getString("pipe7")));
  178.                    line.append("|");
  179.                    line.append(manageEmpty(rs.getString("pipe8")));
  180.                    line.append("|");
  181.                    line.append(manageEmpty(rs.getString("pipe9")));
  182.                    line.append("|");
  183.                    line.append(manageEmpty(rs.getString("pipe10")));
  184.                    line.append("|");
  185.                    line.append(manageEmpty(rs.getString("pipe11")));
  186.                    line.append("|");
  187.                    line.append(manageEmpty(rs.getString("pipe12")));
  188.                    line.append("|");
  189.                    line.append(manageEmpty(rs.getString("pipe13")));
  190.                    line.append("DEVOLUCION|0");
  191.                    line.append("|");
  192.                    line.append("0");
  193.                    line.append("|");
  194.                    line.append("0");
  195.                    line.append("|0");
  196.                                    }
  197.  
  198.               if (this.customerTextField.getText().equals("491")) {
  199.  
  200.  
  201.                 System.out.println(rs.getString("pipe15")+" __ "+rs.getString("pipe16"));
  202.  
  203.                    psu.setString(1, rs.getString("pipe15"));
  204.                    psu.setString(2, rs.getString("pipe16"));
  205.                    psu.executeUpdate();
  206.  
  207. //               }
  208.  
  209.                deliv++;
  210.                line.append(endLine);
  211.                row++;
  212.            }
  213.  
  214.        //    System.out.println("alcanzo a salir");
  215.            qry_visits = " select to_char(ja.dispatch_date,'ddmmyy') as fecha, c.cust_shipping_code,"
  216.                    + " cp.addressee_cust_account,ja.* from journeys_arunico ja left join cnsgnmnt_pieces  cp "
  217.                    + " on  ja.cnsgnmnt_piece_id = cp.cnsgnmnt_piece_id "
  218.                    + " left join consignments c on cp.consignment_id = c.consignment_id"
  219.                    + " where c.cust_shipping_code = '" + csc + "' " // and cp.cnsgnmnt_piece_id = 1667693823
  220.                    + " and ja.customer_id=491 and cp.cnsgnmnt_piece_id not in "
  221.                    + "(select acknowledgment_capture.cnsgnmnt_piece_id from acknowledgment_capture"
  222.                    + " left join cnsgnmnt_pieces on cnsgnmnt_pieces.cnsgnmnt_piece_id=acknowledgment_capture.cnsgnmnt_piece_id"
  223.                    + " where cnsgnmnt_pieces.cnsgnmnt_piece_id=cp.cnsgnmnt_piece_id ) order by ja.cnsgnmnt_piece_id,ja.dispatch_date";
  224.            System.out.println(csc +" todavia llega aca");
  225.            visit = 0;
  226.            int primero = 1;
  227.            String add_acc = "", fecha = "";
  228.  
  229.            rs_aux = st_aux.executeQuery(qry_visits);
  230.            System.out.println(qry_visits);
  231.            while (rs_aux.next()) {
  232.                linea_doc = "";
  233.                if (primero == 1) {
  234.                    add_acc = rs_aux.getString("addressee_cust_account");
  235.                    fecha = rs_aux.getString("fecha");
  236.                    primero = 0;
  237.                }
  238.  
  239.                if (rs_aux.getString("addressee_cust_account").equals(add_acc)) {
  240.  
  241.                    add_acc = rs_aux.getString("addressee_cust_account");
  242.                    fecha = rs_aux.getString("fecha");
  243.                    visit++;
  244.                    continue;
  245. //               } else {
  246. //
  247. //                    line.append(manageEmpty(rs_aux.getString("cust_shipping_code")));
  248. //                    line.append("|");
  249. //                    line.append(manageEmpty(add_acc));
  250. //                    line.append("|");
  251. //                    line.append(manageEmpty("10"));
  252. //                    line.append("|");
  253. //
  254. ////                    if (visit == 0) {
  255. ////                        line.append("00");
  256. ////                        line.append("|");
  257. ////                        line.append("00");
  258. ////                        line.append("|");
  259. ////                    } else if (visit == 1) {
  260. ////                        line.append("60");
  261. ////                        line.append("|");
  262. ////                        line.append("61");
  263. ////                        line.append("|");
  264. ////                    } else if (visit == 2) {
  265. ////                        line.append("60");
  266. ////                        line.append("|");
  267. ////                        line.append("62");
  268. ////                        line.append("|");
  269. ////                    } else {
  270. ////                        line.append("60");
  271. ////                        line.append("|");
  272. ////                        line.append("63");
  273. ////                        line.append("|");
  274. ////                    }
  275. //
  276. ////                  line.append(manageEmpty(fecha)); 11:30
  277. ////                  line.append(manageEmpty("|"));
  278. ////                    line.append("|||||||||||");
  279. //
  280. //                    add_acc = rs_aux.getString("addressee_cust_account");
  281. //                    fecha = rs_aux.getString("fecha");
  282. //
  283. //                    visit = 1;
  284. //
  285. //                    deliv++;
  286. //                    line.append(endLine);
  287. //                    row++;
  288. //
  289. //
  290. //                }
  291.            }
  292.            if (flag_tot == 1) {
  293.  
  294.                line113.append(line);
  295.                line.setLength(0);
  296.  
  297.            } else if (flag_tot == 2) {
  298.  
  299.                line126.append(line);
  300.                line.setLength(0);
  301.  
  302.            } else {
  303.                lineotro.append(line);
  304.                line.setLength(0);
  305.            }
  306.  
  307.            if (flag_tot == 1) {
  308.                total113 = (total113 + deliv);
  309.                deliv = 0;
  310.            } else if (flag_tot == 2) {
  311.                total126 = (total126 + deliv);
  312.                deliv = 0;
  313.            } else {
  314.                totalotro = (totalotro + deliv);
  315.                deliv = 0;
  316.            }
  317.  
  318.  
  319.  
  320.        }
  321.  
  322.        if (this.customerTextField.getText().equals("491")) {
  323.  
  324. //                current = new File(savePath + path + fileName);
  325. //            current = new File(savePath + path + gname_113);
  326. //
  327. //            line113.insert(0, "999999|" + total113 + "|||||||||||||||" + endLine);
  328. //
  329. //           current = new File(savePath + path + gname_126);
  330. //            line126.insert(0, "999999|" + total126 + "|||||||||||||||" + endLine);
  331. //
  332. //
  333. //            current = new File(savePath + path + gname_otro);
  334. //            lineotro.insert(0, "999999|" + totalotro + "|||||||||||||||" + endLine);
  335.  
  336.  
  337.            File dir = new File(savePath + path);
  338.            if (!dir.exists()) {
  339.                dir.mkdir();
  340.            }
  341.            writeFile(line113.toString(), savePath + path + gname_113);
  342.            writeFile(line126.toString(), savePath + path + gname_126);
  343.            writeFile(lineotro.toString(), savePath + path + gname_otro);
  344.        }
  345.  
  346.            }
  347.        deliv = 0;
  348.        line.setLength(0);
  349.        total113 = 0;
  350.        total126 = 0;
  351.        totalotro = 0;
  352.        line113.setLength(0);
  353.        line126.setLength(0);
  354.        lineotro.setLength(0);
  355.  
  356.        conn.commit();
  357.        close(conn);
  358.        close(st);
  359.        close(ps);
  360.        close(psu);  
  361.        close(rs);
  362.        close(ot);
  363.  
  364.        if (files > 0) {
  365.            showMessage("Los archivos se generaron con exito en la ruta " + savePath, "Aviso", JOptionPane.INFORMATION_MESSAGE);
  366.        } else {
  367.            showMessage("No se encontraron registros para los filros especificados", "Error", JOptionPane.ERROR_MESSAGE);
  368.        }
  369.    }
  370.  
  371.     }
  372.  
  373.  


« Última modificación: 16 Junio 2016, 20:25 pm por padre_15 » En línea

+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
Re: crear dos archivos txt mediante un query al server y sentencia IF
« Respuesta #1 en: 16 Junio 2016, 21:03 pm »

si comentas un poco mas tu codigo te lo agradecia...


saludos...


En línea

padre_15

Desconectado Desconectado

Mensajes: 5


Ver Perfil
Re: crear dos archivos txt mediante un query al server y sentencia IF
« Respuesta #2 en: 16 Junio 2016, 21:45 pm »

Aque te refieres a comentar mas el código, esa es toda la clase , para la impresión de los archivos, la mando llamar de boton en una pantalla JFrame para, mediante los update hago el registro, los query solo son para mandar llamar la linea que necesito de unos clientes, al principio empieza la conexión y la termino al final como muestra el codigo, solo que los que nadamas me genera el primer archivo que entra en el primer IF, que es 113 y no el segundo que es 126, no me lo esta generando, y hay datos que si train el 126 pero no me los genera en el txt.............
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[php&mysql]crear query sql mediante formularios
Bases de Datos
twoz 3 7,455 Último mensaje 9 Marzo 2009, 06:42 am
por ^Tifa^
Crear función para hacer query moldeable
PHP
Servia 5 3,657 Último mensaje 3 Febrero 2011, 23:20 pm
por Servia
Leer archivo LOG desde Query SQL Server 2008
Bases de Datos
Shell Root 5 14,631 Último mensaje 1 Diciembre 2011, 12:21 pm
por Novlucker
Crear respuestas de comando mediante archivos bat
Scripting
Dankhrat 7 10,344 Último mensaje 6 Marzo 2014, 17:54 pm
por Dankhrat
Problema al realizar un HAVING en una Query SQL Server 2008
Bases de Datos
Black.scorpion.x 1 2,958 Último mensaje 13 Septiembre 2017, 03:36 am
por rubentexas
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines