Saturday, September 27, 2014

Design Pattern Performance Test

package com.db2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

public class Demo1 {

    PreparedStatement pstmt;
    ResultSet  rset;
    ResultSet rsett;
    Connection connection = null;
   
    static Logger log = Logger.getLogger(
            Demo.class.getName());
   
    public void dataConnection(){
       
        try
        {
          // the db2 driver string
            Class.forName("com.ibm.db2.jcc.DB2Driver");
       
          // the db2 url string
          String url = "jdbc:db2://localhost:50000/mount:currentSchema=mount;currentFunctionPath=mount;";
       
          // get a db2 database connection
          connection = DriverManager.getConnection(url,"db2admin", "db2admin");
         
         
         
          // now do whatever you want to do with the connection
          // ...
          try {

              pstmt = connection.prepareStatement("Select * from evolution ");
          } catch (SQLException exception) {

              System.out.println("wrong parameter");

          }
       
       
         long t1=0;
         long t2=0;
       
       
         t1=System.currentTimeMillis();
       
//         ExecutorService executor = Executors.newCachedThreadPool();
       
       
       
       
//         for(int j=0;j<200;j++){
           
           
         try {
             rsett = pstmt.executeQuery();
         } catch (SQLException exception) {

             System.out.println("wrong parameter");
             connection.rollback();

         }
            while (rsett.next()) {
                String coffeeName = rsett.getString("KUKBNC");
                System.out.println(coffeeName);

            }
//           ResultThread th=new ResultThread();
//          th.setResultThread(rsett);
//          Thread tt=new Thread(th);
//          tt.run();
 
            //Executor
//            log.info("Hello this is an debug message 1");
//            log.info("Hello this is an debug message 2");
//            log.info("Hello this is an debug message 3");
//            log.info("Hello this is an debug message 4");
//            log.info("Hello this is an debug message 5");
//            log.info("Hello this is an info message");
           
      //      ResultThread th=new ResultThread(rsett);
        //    th.setResultThread(rsett);
         

           
          //  executor.execute(th);
       
//            executor.execute(new Runnable() {
//              
//                @Override
//                public void run() {
//                    try{
//                  while(rsett.next()){
//                
//                  }
//                    }catch(Exception e){
//                      e.printStackTrace();
//                  }
//                  
//                }
//            });
           
//            while(rsett.next()){
//              
//            }
           
//            for(int k=0;k<100;k++){
//                System.out.println("test" + k);
//            }
//               while(rsett.next()){
//          
//         //    System.out.println(i);
//         }
       
       
       
//         }
         t2=System.currentTimeMillis();
         System.out.println(t2-t1);

       
          return;
        }
        catch (ClassNotFoundException e)
        {
          e.printStackTrace();
          System.exit(1);
        }
        catch (SQLException e)
        {
          e.printStackTrace();
          System.exit(2);
        }
    }
   
   
    public static void main(String[] args)
    {
        Demo dm=new Demo();
        dm.dataConnection();
   
    }
   
//  
//   public static class ResultThread implements Runnable {
//  
//        ResultSet  rset1;
//      
//        public ResultThread(ResultSet rs){
//            this.rset1 = rs;
//       }
//      
//        public void setResultThread(ResultSet rs){
//            this.rset1 = rs;
//        }
//      @Override
//        public void run() {
//        
//            try{
//            
////          while(rset1.next()){
////        
////          }
//                for(int k=0;k<100;k++){
//                    System.out.println("test" + k);
//                }
//            }catch(Exception e){
//                e.printStackTrace();
//            }
//        }
//    }
   
}

No comments:

Post a Comment