IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Java Services How to refer to database aliases

  • 1.  Java Services How to refer to database aliases

    Posted Fri January 03, 2003 06:13 PM

    I need to write a Java Service that uses JDBC and needs to refer to the Data Sources (Alias) defined in webMethods. The Java Service is run standalone - hence has no inputs from any other services.

    Please let me know how to take care of this.

    thanks in advance.
    KrishnaN


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 2.  RE: Java Services How to refer to database aliases

    Posted Fri January 03, 2003 06:18 PM

    Here is the java code for database connectivity. To reference webMethods session data, soon.
    Thanks

    import java.sql.*;

    public class MetaTest {

    // String defining database connection

    static final String dbURI = “jdbc:odbc:TransactionDB”;

    public static void main(String args)
    throws ClassNotFoundException, SQLException {

     // Connection reference 
    Connection conn = null; 
    
    try { 
    
    // Load database driver 
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
    
    // Make connection 
    conn = DriverManager.getConnection(dbURI); 
    
    // Get the database meta data 
    DatabaseMetaData dmd = conn.getMetaData(); 
    
    // Display information about the database  
    // product and driver 
    
    if (dmd == null) { 
    
    System.out.println("Database meta data not available"); 
    
    } else { 
    
    System.out.println( 
    "Database Product Name   : " + 
    dmd.getDatabaseProductName()); 
    System.out.println( 
    "Database Product Version: " + 
    dmd.getDatabaseProductVersion()); 
    System.out.println( 
    "Database Driver Name    : " + 
    dmd.getDriverName()); 
    System.out.println( 
    "Database Driver Version : " + 
    dmd.getDriverVersion()); 
    } 
    
    } finally { 
    
    // Close connection 
    
    if (conn != null) { 
    try { 
    conn.close(); 
    } catch (SQLException sqlEx) { 
    // ignore 
    } 
    } 
    } 
    

    }
    }


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 3.  RE: Java Services How to refer to database aliases

    Posted Fri January 03, 2003 07:15 PM

    KrishnaN,

    I am assuiming that you want to reference the aliases defined rather than hardcoding the URL, user, password and driver settings in your code. If that is the case then you can just use the service

    wm.server.db:dataSourceGet

    with the database alias as the input and it will return an IData object with the URL, user, password and driver setting in the alias. From there on you can just use simple JDBC code to open a connection.

    Let me know if you need more details.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods