Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package idescat.ralc.rep;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.sql.Connection;
- import java.sql.Date;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.text.SimpleDateFormat;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author mdelgado
- */
- public class NewMain
- {
- private static Connection rep = null, ralc = null;
- private static BufferedWriter wr = null;
- public static int[] taulaResul = new int[10];
- public static int[][][][] tau = new int[2][2][2][2];
- public static void main(String[] args) throws Exception
- {
- try
- {
- String urlDestad = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ndsbeta.idescat.local)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=destad.idescat.local)))";
- rep = DriverManager.getConnection(urlDestad,"rep","rep");
- ralc = DriverManager.getConnection(urlDestad,"regalu","regalu");
- wr = new BufferedWriter(new FileWriter("c:/AlumnesCED/REP-RALC_2015-2016.txt"));
- long start = System.nanoTime();
- PreparedStatement ps = ralc.prepareStatement("select * from vw_ralc");
- ResultSet rs = ps.executeQuery();
- int n = 0;
- long startIni = System.nanoTime();
- start = startIni;
- while ( rs.next())
- {
- n++;
- Ralc vpar = new Ralc(rs);
- String tiden= rs.getString("tiden");
- if ( rs.wasNull() ) tiden = "";
- if ( tiden.equals("DNI")) ;//tractamentDNI(rs);
- else if ( tiden.equals("NIE")) ;//tractamentNIE(rs);
- else if ( tiden.equals("PASS")) tractamentPassaport(rs);
- if ( n % 1000 == 0 )
- {
- System.out.println("Resultats DNI");
- for ( int i=0;i<3;i++)
- {
- System.out.println(" i:" + i + " ---> " + taulaResul[i]);
- }
- System.out.println("REsult trobats DNI");
- for ( int i1=0;i1<2;i1++)
- for ( int i2=0;i2<2;i2++)
- for ( int i3=0;i3<2;i3++)
- for ( int i4=0;i4<2;i4++)
- {
- System.out.println("... " + i1 + i2 + i3 + i4 + " ---- " + tau[i1][i2][i3][i4]);
- }
- }
- }
- rs.close();
- ps.close();
- rep.close();
- ralc.close();
- if ( n % 1000 == 0 )
- {
- System.out.println("Final Resultats DNI");
- for ( int i=0;i<3;i++)
- {
- System.out.println(" i:" + i + " ---> " + taulaResul[i]);
- }
- System.out.println("REsult trobats DNI");
- for ( int i1=0;i1<2;i1++)
- for ( int i2=0;i2<2;i2++)
- for ( int i3=0;i3<2;i3++)
- for ( int i4=0;i4<2;i4++)
- {
- System.out.println("... " + i1 + i2 + i3 + i4 + " ---- " + tau[i1][i2][i3][i4]);
- }
- }
- }
- catch ( Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- try {
- if ( !rep.isClosed()) rep.close();
- if ( !ralc.isClosed()) ralc.close();
- } catch (Exception ex) {
- Logger.getLogger(NewMain.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- private static void tractamentDNI(ResultSet rs) throws Exception
- {
- try
- {
- taulaResul[0]++;
- String iden = rs.getString("iden");
- if ( rs.wasNull()) iden = "";
- int id_nom = rs.getInt("id_nom_final");
- int id_ape1 = rs.getInt("id_ape1_final");
- int id_ape2 = rs.getInt("id_ape2_final");
- Date dr = rs.getDate("data_naix");
- if ( rs.wasNull() ) dr = null;
- String fnac = new SimpleDateFormat ("yyyyMMdd").format(dr);
- String dni = "";
- if ( iden.length() == 9 ) dni = iden.substring(0, 8);
- else dni = iden;
- PreparedStatement prep = rep.prepareStatement("select fnac, id_nomf, id_ape1f, id_ape2f from hab_nia_proves where tiden='1' and iden=? group by fnac, id_nomf, id_ape1f, id_ape2f");
- prep.setString(1,dni);
- ResultSet rrep = prep.executeQuery();
- int res = 0;
- boolean igual = false;
- int i1=0, i2=0, i3=0, i4=0;
- if ( rrep.next() && !igual)
- {
- res++;
- String fnacREP = rrep.getString("fnac");
- if ( fnac.equals(fnacREP)) i1 = 1;
- int id_nomREP = rrep.getInt("id_nomf");
- if ( id_nom == id_nomREP ) i2 = 1;
- int id_ape1REP = rrep.getInt("id_ape1f");
- if ( id_ape1 == id_ape1REP ) i3 = 1;
- int id_ape2REP = rrep.getInt("id_ape2f");
- if ( id_ape2 == id_ape2REP ) i4 = 1;
- tau[i1][i2][i3][i4]++;
- }
- if ( res == 0 ) taulaResul[1]++;
- else taulaResul[2]++;
- rrep.close();
- prep.close();
- }
- catch ( Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- }
- private static void tractamentNIE(ResultSet rs) throws Exception
- {
- try
- {
- taulaResul[0]++;
- String iden = rs.getString("iden");
- if ( rs.wasNull()) iden = "";
- int id_nom = rs.getInt("id_nom_final");
- int id_ape1 = rs.getInt("id_ape1_final");
- int id_ape2 = rs.getInt("id_ape2_final");
- Date dr = rs.getDate("data_naix");
- if ( rs.wasNull() ) dr = null;
- String fnac = new SimpleDateFormat ("yyyyMMdd").format(dr);
- String dni = "";
- String lextr = "";
- if ( iden.length() == 9 )
- {
- lextr = iden.substring(0, 1);
- dni = "0" + iden.substring(1, 8);
- }
- else dni = iden;
- PreparedStatement prep = rep.prepareStatement("select fnac, id_nomf, id_ape1f, id_ape2f from hab_nia_proves where tiden='3' and lextr=? and iden=? group by fnac, id_nomf, id_ape1f, id_ape2f");
- prep.setString(1,lextr.toUpperCase());
- prep.setString(2,dni);
- ResultSet rrep = prep.executeQuery();
- int res = 0;
- boolean igual = false;
- int i1=0, i2=0, i3=0, i4=0;
- if ( rrep.next() && !igual)
- {
- res++;
- String fnacREP = rrep.getString("fnac");
- if ( fnac.equals(fnacREP)) i1 = 1;
- int id_nomREP = rrep.getInt("id_nomf");
- if ( id_nom == id_nomREP ) i2 = 1;
- int id_ape1REP = rrep.getInt("id_ape1f");
- if ( id_ape1 == id_ape1REP ) i3 = 1;
- int id_ape2REP = rrep.getInt("id_ape2f");
- if ( id_ape2 == id_ape2REP ) i4 = 1;
- tau[i1][i2][i3][i4]++;
- }
- if ( res == 0 ) taulaResul[1]++;
- else taulaResul[2]++;
- rrep.close();
- prep.close();
- }
- catch ( Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- }
- private static void tractamentPassaport(ResultSet rs) throws Exception
- {
- try
- {
- taulaResul[0]++;
- String iden = rs.getString("iden");
- if ( rs.wasNull()) iden = "";
- int id_nom = rs.getInt("id_nom_final");
- int id_ape1 = rs.getInt("id_ape1_final");
- int id_ape2 = rs.getInt("id_ape2_final");
- Date dr = rs.getDate("data_naix");
- if ( rs.wasNull() ) dr = null;
- String fnac = new SimpleDateFormat ("yyyyMMdd").format(dr);
- PreparedStatement prep = rep.prepareStatement("select fnac, id_nomf, id_ape1f, id_ape2f from hab_nia_proves where tiden='2' and ndocu=? group by fnac, id_nomf, id_ape1f, id_ape2f");
- prep.setString(1,iden);
- ResultSet rrep = prep.executeQuery();
- int res = 0;
- boolean igual = false;
- int i1=0, i2=0, i3=0, i4=0;
- if ( rrep.next() && !igual)
- {
- res++;
- String fnacREP = rrep.getString("fnac");
- if ( fnac.equals(fnacREP)) i1 = 1;
- int id_nomREP = rrep.getInt("id_nomf");
- if ( id_nom == id_nomREP ) i2 = 1;
- int id_ape1REP = rrep.getInt("id_ape1f");
- if ( id_ape1 == id_ape1REP ) i3 = 1;
- int id_ape2REP = rrep.getInt("id_ape2f");
- if ( id_ape2 == id_ape2REP ) i4 = 1;
- tau[i1][i2][i3][i4]++;
- }
- if ( res == 0 ) taulaResul[1]++;
- else taulaResul[2]++;
- rrep.close();
- prep.close();
- }
- catch ( Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement