DB2 Run from JavaAgent

/**
 * Created: 2012.10.28.1.40.PM
 * DB2AddDataBean JavaAgent
 * DB2 Data Loading Bean
 */
package com.dokoll.solutions.inc.db2.test;

/**
 * @author Dököll Solutions, Inc.
 * @version 2012.10.28.1.40.PM
 *
 */
import java.sql.*;

public class DB2AddDataBean {
  public static void main(String[] args) throws Exception {
	  
	System.out.println("Entering Driver connection...");
    Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
	System.out.println("Entering actual connection...");
    Connection conn =  DriverManager.getConnection("jdbc:db2://localhost:50000/DOMINODB","db2admin","yourpassport");
	System.out.println("Begin statement...");
    Statement stat = conn.createStatement();
	System.out.println("Entering query...");
    PreparedStatement prep = conn.prepareStatement("insert into DB2ADMIN.USER_DETAILS values (?,?,?, ?, ?, ?, ?, ?, ?, ?, ?)");
   
//    //Added Data for report
//    //2012.10.28.9.03.PM   
    prep.setString(1, "XYZ001EBC");
    prep.setString(2, "username13");
    prep.setString(3, "XYZ001EBCBOS");
    prep.setString(4, "Boston");
    prep.setString(5, "XYZ001EBCNAME13");
    prep.setString(6, "01/01/1943");
    prep.setString(7, "70");
    prep.setString(8, "GuntherBerg, Inc.");
    prep.setString(9, "33335555899");
    prep.setString(10, "2000.01.11.11.10.PM");
    prep.setString(11, "Commonwealth");
    prep.addBatch();
    prep.setString(1, "XYZ002FBC");
    prep.setString(2, "username14");
    prep.setString(3, "XYZ002FBCCAN");
    prep.setString(4, "Montréal");
    prep.setString(5, "XYZ002FBCNAME14");
    prep.setString(6, "01/01/1980");
    prep.setString(7, "39");
    prep.setString(8, "SmashBook, Inc.");
    prep.setString(9, "99994444811");
    prep.setString(10, "2010.12.19.1.10.AM");
    prep.setString(11, "Oh Canada");
    prep.addBatch();

    System.out.println("Values added...");
    conn.setAutoCommit(false);
    prep.executeBatch();
    conn.setAutoCommit(true);
    ResultSet rs = stat.executeQuery("select * from DB2ADMIN.USER_DETAILS");
    System.out.println("Submitting to console...");
    while (rs.next()) {
    System.out.println("ID   |"+"AllegationCode|"+"Office       |"+"Investigator|"+"DateOpen    |"+"Age  |"+"AllegationNumber|"+"Licensee       |"+"Subject              |"+"Region    |");
    System.out.println(rs.getString("ID")+"     |"+rs.getString("AllegationCode")+"     |"+rs.getString("Office")+"     |"+ rs.getString("Investigator")+"   |"+ rs.getString("DateOpen")+"  |"+ rs.getString("Age")+ "   |"+ rs.getString("AllegationNumber")+ "      |"+ rs.getString("Licensee")+"    |" +rs.getString("Subject")+  "  |"+ rs.getString("Region"));

    }
    rs.close();
    conn.close();
  }
}





Create a DB2 database, configure a DataSource, connect to the back-end, add records and retrieve DB2 data using a JavaAgent.  Information that can be used to load records into Lotus Notes Domino Database located on your C Drive as documents; data that can also be accessed via Xpages Application...

Java
Köll S Cherizard
November 4, 2012 2:55 AM
Rating
49

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...