Friday, February 7, 2014

Java Connect to Informatica Data Service using jdbc

We had a requirement to connect to informatica and get the values from the virtual table.Using the below java code we were able to connect and fetch the records.


The Infadsjdbc.jar will need to be kept in the classpath.


 package com.sample;  
 import java.sql.Connection;  
 import java.sql.DriverManager;  
 import java.sql.ResultSet;  
 import java.sql.SQLException;  
 import java.sql.Statement;  
 import java.util.ArrayList;  
 import java.util.List;  
 /**  
 * @author venky  
 *  
 */   
     public class ConnectInfaImpl{   
     static final String DB_URL = "jdbc:informatica:sqlds//@hostname:port?dis=DIS&sqlds=N_Dummy.DS_N_Dummy";  
     static final String USER = "Administrator";  
     static final String PASS = "********";  
     public static void main(String[] args) {  
     Connection conn = null;  
     Statement stmt = null;  
     List al =null;  
     try{  
      //STEP 2: Register JDBC driver  
      Class.forName("com.informatica.ds.sql.jdbcdrv.INFADriver");  
      //STEP 3: Open a connection  
      System.out.println("Connecting to database...");  
       System.out.println("DB_URL==>"+DB_URL);  
       System.out.println("USER==>"+USER);  
       System.out.println("PASS==>"+PASS);  
       System.out.println("Connecting to database...");  
       conn = DriverManager.getConnection(DB_URL,USER,PASS);  
      //STEP 4: Execute a query  
      System.out.println("Creating statement...");  
      stmt = conn.createStatement();  
      String sql;  
      sql = "select * from my_table";  
      ResultSet rs = stmt.executeQuery(sql);  
      //STEP 5: Extract data from result set  
       al =new ArrayList();  
      while(rs.next()){  
            System.out.println("result==:"+rs.next());  
      }  
     }catch(SQLException se){  
      //Handle errors for JDBC  
      se.printStackTrace();  
     }catch(Exception e){  
      //Handle errors for Class.forName  
      e.printStackTrace();  
     }finally{  
      //finally block used to close resources  
      try{  
        if(stmt!=null)  
         stmt.close();  
      }catch(SQLException se2){  
        se2.printStackTrace();  
      }  
      try{  
        if(conn!=null)  
         conn.close();  
      }catch(SQLException se){  
        se.printStackTrace();  
      }  
     }  
     System.out.println("Goodbye!");  
   }  
   }  

2 comments:

  1. This is a very good example for influence of Java on Informatica. Thanks for sharing.


    Best Informatica Training In Chennai

    ReplyDelete
  2. We have and are continuing to develop better technologies to eradicate hunger and the threat of a Pandemic today. But, the resolve to use the technologies that we have and develop more for the betterment of all of mankind is predicated by the implementation of National Economic Reform's Science and Technology Directive.guarantor loans

    ReplyDelete