kjelavankal

PI JDBC Connection Pooling

Discussion created by kjelavankal on Oct 13, 2014
Latest reply on Oct 13, 2014 by michaelh

Hi I am trying to use com.osisoft.jdbc2.* classes for PI JDBC Connection Pooling but i am getting the following error. Can you please suggest a resolution and a similar sample code. 

 

cannot access com.osisoft.jdbc2.PIJDBCDataSource
bad class file: C:\Program Files\PIPC\JDBC\PIJDBCDriver.jar(com/osisoft/jdbc2/PIJDBCDataSource.class)
class file has wrong version 50.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
          PIJDBCDataSource pds =new PIJDBCDataSource(connectionString);
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

 

Please find my code

 

public static synchronized Connection getConnection(String piServer) {
    Connection conn = null;
    boolean haveConnection = false;
    boolean error = false;
    while (!haveConnection) {
    try {
       
         //Load the properties file to get critical DB connection info
          Properties prop = getProperties();

 

          //If prop object is null, file not found with data needed to connect database
          if (prop == null) {
            return null;
          }
  
          //Set the critical properties need to create the connections
          String connectionString = CSIIProperties.getProperty("PI_DB_CONNECT");
          String dataSource ="Data Source= " + piServer;
          connectionString=connectionString + dataSource;
         
          if (connectionString == null || connectionString.trim().equals("") ){
            return null;
          }
         
          PIJDBCDataSource pds =new PIJDBCDataSource(connectionString);
          pds.setLogLevel(99);
          pds.setLogFile("D:\\JDBC2Test.log");
         
          conn =pds.getConnection(prop.getProperty("PIUN"), prop.getProperty("PIPW"));
  
        if (conn == null) {
          System.out.println("ERROR OBTAINING DATABASE CONNECTION: Cache returned NULL");
                
          //Try to create connection again in 5 sec.
          System.out.println("Will again attempt to create connection in 5 Sec.");
          haveConnection = false;
          error = true;
          try{Thread.sleep(5000);} catch (Exception ex) {Logging.logException(ex, "Error trying to sleep for DB Connection");}
        } else {
          haveConnection = true;
        }

 

        //Catch any SQL Exceptions caused by creating the connections in the DB
      } catch (SQLException e) {
        //Logging.logSQLException(e);
        System.out.println("ERROR OBTAINING DATABASE CONNECTION: " + e.getMessage());
        //Try to create connection again in 5 sec.
        System.out.println("Will again attempt to create connection in 5 Sec.");
        haveConnection = false;
        error = true;
        try{Thread.sleep(5000);} catch (Exception ex) {Logging.logException(ex, "Error trying to sleep for DB Connection");}
      }
      catch (Exception e){
          e.printStackTrace();
      }
    }
    if (error) {
      System.out.println("Connection was obtained.");
    }
    return conn;
  }

 

 

 

 

Outcomes