Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.39 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package idescat.ralc.rep;
  7.  
  8. import java.io.BufferedWriter;
  9. import java.io.FileWriter;
  10. import java.sql.Connection;
  11. import java.sql.Date;
  12. import java.sql.DriverManager;
  13. import java.sql.PreparedStatement;
  14. import java.sql.ResultSet;
  15. import java.text.SimpleDateFormat;
  16. import java.util.logging.Level;
  17. import java.util.logging.Logger;
  18.  
  19. /**
  20. *
  21. * @author mdelgado
  22. */
  23. public class NewMain
  24. {
  25. private static Connection rep = null, ralc = null;
  26. private static BufferedWriter wr = null;
  27.  
  28. public static int[] taulaResul = new int[10];
  29. public static int[][][][] tau = new int[2][2][2][2];
  30. public static void main(String[] args) throws Exception
  31. {
  32. try
  33. {
  34. String urlDestad = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ndsbeta.idescat.local)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=destad.idescat.local)))";
  35. rep = DriverManager.getConnection(urlDestad,"rep","rep");
  36. ralc = DriverManager.getConnection(urlDestad,"regalu","regalu");
  37.  
  38. wr = new BufferedWriter(new FileWriter("c:/AlumnesCED/REP-RALC_2015-2016.txt"));
  39.  
  40. long start = System.nanoTime();
  41.  
  42. PreparedStatement ps = ralc.prepareStatement("select * from vw_ralc");
  43. ResultSet rs = ps.executeQuery();
  44. int n = 0;
  45. long startIni = System.nanoTime();
  46. start = startIni;
  47. while ( rs.next())
  48. {
  49. n++;
  50. Ralc vpar = new Ralc(rs);
  51. String tiden= rs.getString("tiden");
  52. if ( rs.wasNull() ) tiden = "";
  53. if ( tiden.equals("DNI")) ;//tractamentDNI(rs);
  54. else if ( tiden.equals("NIE")) ;//tractamentNIE(rs);
  55. else if ( tiden.equals("PASS")) tractamentPassaport(rs);
  56.  
  57.  
  58.  
  59. if ( n % 1000 == 0 )
  60. {
  61. System.out.println("Resultats DNI");
  62. for ( int i=0;i<3;i++)
  63. {
  64. System.out.println(" i:" + i + " ---> " + taulaResul[i]);
  65. }
  66.  
  67. System.out.println("REsult trobats DNI");
  68. for ( int i1=0;i1<2;i1++)
  69. for ( int i2=0;i2<2;i2++)
  70. for ( int i3=0;i3<2;i3++)
  71. for ( int i4=0;i4<2;i4++)
  72. {
  73. System.out.println("... " + i1 + i2 + i3 + i4 + " ---- " + tau[i1][i2][i3][i4]);
  74. }
  75. }
  76.  
  77.  
  78. }
  79. rs.close();
  80. ps.close();
  81. rep.close();
  82. ralc.close();
  83.  
  84. if ( n % 1000 == 0 )
  85. {
  86. System.out.println("Final Resultats DNI");
  87. for ( int i=0;i<3;i++)
  88. {
  89. System.out.println(" i:" + i + " ---> " + taulaResul[i]);
  90. }
  91.  
  92. System.out.println("REsult trobats DNI");
  93. for ( int i1=0;i1<2;i1++)
  94. for ( int i2=0;i2<2;i2++)
  95. for ( int i3=0;i3<2;i3++)
  96. for ( int i4=0;i4<2;i4++)
  97. {
  98. System.out.println("... " + i1 + i2 + i3 + i4 + " ---- " + tau[i1][i2][i3][i4]);
  99. }
  100. }
  101.  
  102.  
  103. }
  104. catch ( Exception e)
  105. {
  106. e.printStackTrace();
  107. }
  108. finally
  109. {
  110. try {
  111. if ( !rep.isClosed()) rep.close();
  112. if ( !ralc.isClosed()) ralc.close();
  113. } catch (Exception ex) {
  114. Logger.getLogger(NewMain.class.getName()).log(Level.SEVERE, null, ex);
  115. }
  116.  
  117. }
  118. }
  119.  
  120. private static void tractamentDNI(ResultSet rs) throws Exception
  121. {
  122. try
  123. {
  124. taulaResul[0]++;
  125.  
  126. String iden = rs.getString("iden");
  127. if ( rs.wasNull()) iden = "";
  128. int id_nom = rs.getInt("id_nom_final");
  129. int id_ape1 = rs.getInt("id_ape1_final");
  130. int id_ape2 = rs.getInt("id_ape2_final");
  131. Date dr = rs.getDate("data_naix");
  132. if ( rs.wasNull() ) dr = null;
  133.  
  134. String fnac = new SimpleDateFormat ("yyyyMMdd").format(dr);
  135.  
  136. String dni = "";
  137. if ( iden.length() == 9 ) dni = iden.substring(0, 8);
  138. else dni = iden;
  139.  
  140.  
  141. 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");
  142. prep.setString(1,dni);
  143. ResultSet rrep = prep.executeQuery();
  144. int res = 0;
  145. boolean igual = false;
  146. int i1=0, i2=0, i3=0, i4=0;
  147. if ( rrep.next() && !igual)
  148. {
  149. res++;
  150. String fnacREP = rrep.getString("fnac");
  151. if ( fnac.equals(fnacREP)) i1 = 1;
  152.  
  153. int id_nomREP = rrep.getInt("id_nomf");
  154. if ( id_nom == id_nomREP ) i2 = 1;
  155.  
  156. int id_ape1REP = rrep.getInt("id_ape1f");
  157. if ( id_ape1 == id_ape1REP ) i3 = 1;
  158.  
  159. int id_ape2REP = rrep.getInt("id_ape2f");
  160. if ( id_ape2 == id_ape2REP ) i4 = 1;
  161.  
  162. tau[i1][i2][i3][i4]++;
  163. }
  164.  
  165. if ( res == 0 ) taulaResul[1]++;
  166. else taulaResul[2]++;
  167.  
  168. rrep.close();
  169. prep.close();
  170.  
  171.  
  172.  
  173.  
  174.  
  175. }
  176. catch ( Exception e)
  177. {
  178. e.printStackTrace();
  179. throw e;
  180. }
  181. }
  182.  
  183. private static void tractamentNIE(ResultSet rs) throws Exception
  184. {
  185. try
  186. {
  187. taulaResul[0]++;
  188.  
  189. String iden = rs.getString("iden");
  190. if ( rs.wasNull()) iden = "";
  191. int id_nom = rs.getInt("id_nom_final");
  192. int id_ape1 = rs.getInt("id_ape1_final");
  193. int id_ape2 = rs.getInt("id_ape2_final");
  194. Date dr = rs.getDate("data_naix");
  195. if ( rs.wasNull() ) dr = null;
  196.  
  197. String fnac = new SimpleDateFormat ("yyyyMMdd").format(dr);
  198.  
  199. String dni = "";
  200. String lextr = "";
  201. if ( iden.length() == 9 )
  202. {
  203. lextr = iden.substring(0, 1);
  204. dni = "0" + iden.substring(1, 8);
  205. }
  206. else dni = iden;
  207.  
  208.  
  209. 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");
  210. prep.setString(1,lextr.toUpperCase());
  211. prep.setString(2,dni);
  212. ResultSet rrep = prep.executeQuery();
  213. int res = 0;
  214. boolean igual = false;
  215. int i1=0, i2=0, i3=0, i4=0;
  216. if ( rrep.next() && !igual)
  217. {
  218. res++;
  219. String fnacREP = rrep.getString("fnac");
  220. if ( fnac.equals(fnacREP)) i1 = 1;
  221.  
  222. int id_nomREP = rrep.getInt("id_nomf");
  223. if ( id_nom == id_nomREP ) i2 = 1;
  224.  
  225. int id_ape1REP = rrep.getInt("id_ape1f");
  226. if ( id_ape1 == id_ape1REP ) i3 = 1;
  227.  
  228. int id_ape2REP = rrep.getInt("id_ape2f");
  229. if ( id_ape2 == id_ape2REP ) i4 = 1;
  230.  
  231. tau[i1][i2][i3][i4]++;
  232. }
  233.  
  234. if ( res == 0 ) taulaResul[1]++;
  235. else taulaResul[2]++;
  236.  
  237. rrep.close();
  238. prep.close();
  239.  
  240.  
  241.  
  242.  
  243.  
  244. }
  245. catch ( Exception e)
  246. {
  247. e.printStackTrace();
  248. throw e;
  249. }
  250. }
  251.  
  252. private static void tractamentPassaport(ResultSet rs) throws Exception
  253. {
  254. try
  255. {
  256. taulaResul[0]++;
  257.  
  258. String iden = rs.getString("iden");
  259. if ( rs.wasNull()) iden = "";
  260. int id_nom = rs.getInt("id_nom_final");
  261. int id_ape1 = rs.getInt("id_ape1_final");
  262. int id_ape2 = rs.getInt("id_ape2_final");
  263. Date dr = rs.getDate("data_naix");
  264. if ( rs.wasNull() ) dr = null;
  265.  
  266. String fnac = new SimpleDateFormat ("yyyyMMdd").format(dr);
  267.  
  268. 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");
  269. prep.setString(1,iden);
  270. ResultSet rrep = prep.executeQuery();
  271. int res = 0;
  272. boolean igual = false;
  273. int i1=0, i2=0, i3=0, i4=0;
  274. if ( rrep.next() && !igual)
  275. {
  276. res++;
  277. String fnacREP = rrep.getString("fnac");
  278. if ( fnac.equals(fnacREP)) i1 = 1;
  279.  
  280. int id_nomREP = rrep.getInt("id_nomf");
  281. if ( id_nom == id_nomREP ) i2 = 1;
  282.  
  283. int id_ape1REP = rrep.getInt("id_ape1f");
  284. if ( id_ape1 == id_ape1REP ) i3 = 1;
  285.  
  286. int id_ape2REP = rrep.getInt("id_ape2f");
  287. if ( id_ape2 == id_ape2REP ) i4 = 1;
  288.  
  289. tau[i1][i2][i3][i4]++;
  290. }
  291.  
  292. if ( res == 0 ) taulaResul[1]++;
  293. else taulaResul[2]++;
  294.  
  295. rrep.close();
  296. prep.close();
  297.  
  298.  
  299.  
  300.  
  301.  
  302. }
  303. catch ( Exception e)
  304. {
  305. e.printStackTrace();
  306. throw e;
  307. }
  308. }
  309.  
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement