Advertisement
Guest User

Untitled

a guest
Jan 26th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.72 KB | None | 0 0
  1. package BDScripts;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10.  
  11. import DBClasses.Client;
  12. import DBClasses.Device;
  13.  
  14. public class IndexChecker
  15. {
  16.  
  17.     private int counterS, counterE ;
  18.     private Connection myConn;
  19.  
  20.     public IndexChecker ()
  21.     {
  22.         try {
  23.             myConn = DriverManager.getConnection("jdbc:mysql://localhost:3307/serwispusty", "root", "servroot");
  24.         } catch (SQLException e) {
  25.             // TODO Auto-generated catch block
  26.             e.printStackTrace();
  27.         }
  28.        
  29.        
  30.     }
  31.    
  32.     public void checkIndexesModel ()
  33.     {
  34.         long startnoInd, endnoInd, startInd, endInd, resnoInd, resInd, res;
  35.         ResultSet resultsInd, resultsnoInd;
  36.         try
  37.         {
  38.             Statement keysStatement0 = myConn.createStatement();
  39.             Statement keysStatement1 = myConn.createStatement();
  40.             Statement selectStatement1 = myConn.createStatement();
  41.             Statement selectStatement2 = myConn.createStatement();
  42.            
  43.             //
  44.             startnoInd = System.nanoTime(); //System.currentTimeMillis();
  45.             resultsnoInd = selectStatement2.executeQuery("select * from serwispusty.urzadzenie where Model = 'B6726'");    //("select * from serwispusty.urzadzenie where Model like 'B%'");
  46.             while (resultsnoInd.next())
  47.             {
  48.                 ;
  49.             }
  50.             endnoInd = System.nanoTime(); //System.currentTimeMillis();
  51.            
  52.             res = endnoInd - startnoInd;
  53.             //
  54.            
  55.            
  56.             keysStatement0.executeUpdate("create index by_model on serwispusty.urzadzenie (Model)");
  57.             startInd = System.nanoTime(); //System.currentTimeMillis();    
  58.             resultsInd = selectStatement2.executeQuery("select * from serwispusty.urzadzenie where Model = 'B6726'");
  59.             while (resultsInd.next())
  60.             {
  61.                 ;
  62.             }
  63.             endInd = System.nanoTime(); //System.currentTimeMillis();
  64.             keysStatement1.executeUpdate("ALTER TABLE serwispusty.urzadzenie DROP INDEX by_model");
  65.             startnoInd = System.nanoTime(); //System.currentTimeMillis();
  66.             resultsnoInd = selectStatement2.executeQuery("select * from serwispusty.urzadzenie where Model = 'B6726'");
  67.             while (resultsnoInd.next())
  68.             {
  69.                 ;
  70.             }
  71.             endnoInd = System.nanoTime(); //System.currentTimeMillis();
  72.             resnoInd = endnoInd - startnoInd;
  73.             resInd = endInd - startInd;
  74.             System.out.println("Czas bez ind: " + resnoInd);
  75.             System.out.println("Czas z ind  : " + resInd);
  76.             System.out.println("spr         : " + res);
  77.        
  78.         }
  79.         catch ( Exception e)
  80.         {
  81.             System.out.println("Blad");
  82.         }
  83.        
  84.     }
  85.    
  86.  
  87.     public static void main(String[] args)
  88.     {
  89.         IndexChecker obj = new IndexChecker();
  90.         System.out.println("Czasy sprawdzenia modelu");
  91.         obj.checkIndexesModel();
  92.         System.out.println("///////////////////////////////////////////////");
  93.  
  94.  
  95.     }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement