Standalone java application that calls Db2

Hi,
I am trying to use coherence in my standalone java
application that makes JDBC calls to Db2.
The sql statemet is like below:
select lastName,firstName from employee where empNo=2224;
In the application,I would read from the flat file say
200 account numbers and query the database.
If I have queried the database already with the given
account,I want to retreive from the cache.
I am having real trouble in getting this work with
coherence software.
Any psudo code in this regard will help me a lot.
Thanks
DJon

Hi Jon,
Thanks for the mail.I am struck in
implementing the coherence in the sample program.
any help in this regard is appreciated.
Thanks
DJon
Below is the sample program that works without coherence.go to db2 and get the information.
import java.sql.*;
import java.util.*;
public class DB2Client
static void printColumn(String in)
System.out.print(in);
System.out.print(" | ");
public static void main(String[] args)
Driver myDriver = null;
Connection myConnection = null;
try
myDriver =
(Driver)Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
myConnection =
DriverManager.getConnection("jdbc:db2:sample","dujon","jeff");
PreparedStatement myStatement
= myConnection.prepareStatement("SELECT
empno,firstnme,lastname FROM employee where empno > ?");
myStatement.setString(1,"00");
ResultSet
myResults=myStatement.executeQuery();
while (myResults.next())
printColumn(myResults.getString("empno") + "");
printColumn(myResults.getString("firstnme") + "");
printColumn(myResults.getString("lastname"));
System.out.println();
} catch (Exception e)
e.printStackTrace();
} finally
try
if (myConnection != null)
myConnection.close();
} catch (Exception e)
Now,to implement the above sample with
coherence I have written 2 programs.
1. TangosolDB2Cache.java
2. TestDB2Cache.java
import com.tangosol.net.cache.CacheStore;
import com.tangosol.util.Base;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
* An example implementation of CacheStore
* interface.
* @author erm 2003.05.01
public class TangosolDB2Cache extends
Base implements CacheStore
// ----- constructors
* Constructs DBCacheStore for a given
database table.
* @param sTableName the db table name
public TangosolJDBCCache(String
sTableName)
m_sTableName = sTableName;
configureConnection();
     * Set up the DB connection.
     protected void configureConnection()
          try
Class.forName("com.ibm.db2.jcc.DB2Driver");
               m_con =
DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
               m_con.setAutoCommit(true);
          catch (Exception e)
               throw ensureRuntimeException(e,
"Connection failed");
     // ---- accessors
* Obtain the name of the table this
CacheStore is persisting to.
* @return the name of the table this
CacheStore is persisting to
public String getTableName()
return m_sTableName;
* Obtain the connection being used to
connect to the database.
* @return the connection used to
connect to the database
public Connection getConnection()
return m_con;
// ----- CacheStore Interface
* Return the value associated with the
specified key, or null if the
* key does not have an associated
value in the underlying store.
* @param oKey key whose associated
value is to be returned
* @return the value associated with
the specified key, or
* <tt>null</tt> if no value is
available for that key
public Object load(Object oKey)
Integer iKey = (Integer)key;
     return query("select
lastName,firstName from employee where empNo = " + iKey);
* Store the specified value under the
specific key in the underlying
* store. This method is intended to
support both key/value creation
* and value update for a specific key.
* @param oKey key to store the
value under
* @param oValue value to be stored
* @throws
UnsupportedOperationException if this implementation or the
* underlying store is
read-only
public void store(Object oKey, Object
oValue)
          mycacheTable(oKey,oValue);
public void erase(Object oKey)
     public void eraseAll(Collection
colKeys)
          throw new
UnsupportedOperationException();
     public Map loadAll(Collection colKeys)
          throw new
UnsupportedOperationException();
     public void storeAll(Map mapEntries)
          throw new
UnsupportedOperationException();
     // ----- data members
     Hashtable mycacheTable = new Hashtable(1000);
     * The connection.
     protected Connection m_con;
     * The db table name.
     protected String m_sTableName;
     * Driver class name.
     private static final String DB_DRIVER =
"org.gjt.mm.mysql.Driver";
     * Connection URL.
     private static final String DB_URL =
"jdbc:db2:sample";
     * User name.
     private static final String DB_USERNAME =
"dujon";
     * Password.
     private static final String DB_PASSWORD =
"jeff";
TESTING THE ABOVE PROGRAM
import com.tangosol.net.cache.CacheStore;
import com.tangosol.util.Base;
import
com.tangosol.net.cache.MapCacheStore;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class TestDB2Cache {
     public static void main(String args[]){
                    TangosolJDBCCache mycache = new
TangosolDB2Cache("employee");
                    Connection
con=mycache.configureConnection();
                    MapCacheStore cacheStuff = new
MapCacheStore(HashMap hmap);
                    String[] employeeNumbers =
{"000010","000020","000030","000040","000050"};
                              // find whether it has been cached already
                                   for(int
i=0;i<employeeNumbers.length();i++){
                                   oCurValue =
cacheStuff.load(employeeNumbers);
                                   if(oCurValue == null){
                                        // execute SQL statement
                                        con.executeQuery(oCurKey);
                                   else
                                        //get from cache the values and return
                                        cacheStuff.load(oCurKey);

Similar Messages

  • How to make an standalone java application that uses mysql driver

    Hi,
    I have an application that makes connection to a mysql database, on my computer, I set on classpath the driver address, so everithing works fine.
    The problem is that I want to execute my application from other computers, where the classpath does not have the drivers.
    So my question is how can I package the driver? so, everybody can run my application from a Jar, for example.
    thanks in advance,
    - Susana

    Nobody answered me, but I post the solution I found, that maybe can help somebody else with this problem:
    I packed all my application sources (.class) and the drivers sources (.jar) with the tool: FAT JAR. It is an Eclipse plug-in. And now I can run mi application from the resulting Jar in other machines without installing the conector.
    Bye,
    - Susana

  • Can we call a webservice  using standalone java application  ?

    Hi friends,
                   Can we call configurd webservice in xi , using standalone java application by just giving url of webservice ?
                  OR
                  Only by means of WEBDynapro we can call  ?
                    Can you please tell me the answer for this .
    Regards .,
    V.Rangarajan

    HI Ranga Rajan
    well, If at all if you have webservice...you can import that werbserivce as External definition in to IR.
    How to import:
    1) Go to IR and and move to your requied component and there you can see the option called imported objects...select on imported objects where you can give the name and you can select the webservices which you want to use it.
    2) Hope you are aware of that a werbservice will have the request and response.
    3) Create the mapping program accroding to your requirement.
    Go through blogs of Bhavesh and Naveen which talks about calling webservice in a specific condition:
    Webservice Calls From a User Defined Function - /people/bhavesh.kantilal/blog/2006/11/20/webservice-calls-from-a-user-defined-function
    Consuming/Calling webservices from DataBases - /people/sap.user72/blog/2005/10/20/consumingcalling-webservices-from-databases
    Also check this help file on Web Services:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/336365d3-0401-0010-9884-a651295aeaa9
    Cheers..
    Vasu
    <i>** Reward Points if found useful **</i>

  • How to get Portal user from a standalone Java application

    Hi,
    I have a standalone Java application from where I need to fetch the Portal User Information like userid and email id.
    I am using the below line of code
    iUser = UMFactory.getUserFactory().getUserByLogonID("e017939");
    I have included the jar file com.sap.security.api , But it was giving me the below exception
    java.lang.NoClassDefFoundError: com/sap/tc/logging/Location
         at com.sap.security.api.UMFactory.<clinit>(UMFactory.java:55)
         at com.am.wcas.java.mailscheduler.kmaccess.FetchDataFromKM.getiUser(FetchDataFromKM.java:29)
         at com.am.ScheduleEmails.main(ScheduleEmails.java:89)
    and I am getting a pop Up message from the Java Virtual Machine Launcher, saying a Fatal Exception has occured and the Program will exit.
    Then I went throught he SDN threads and they asked me to include the
    logging.jar and com.sap.security.perm.api .
    I Included them, then also, it is giving me Exception
    java.lang.NoClassDefFoundError: com/sap/engine/lib/logging/LoggingHelper
         at com.sap.security.api.UMFactory.<clinit>(UMFactory.java:56)
         at com.am.FetchKMData.main(FetchKMData.java:30)
    Exception in thread "main"
    and I am getting a pop Up message from the Java Virtual Machine Launcher, saying a Fatal Exception has occured and the Program will exit.
    Kindly let me know if it is possible to access the User info using UMFactory in a standalone Java application. If yes kindly let me know where i am going wrong.
    Regards,
    Shilpa B.V

    Hi Shilpa,
    1. Check that you have added com.sap.security.api within the Your Project>Libraries folder (under navigation tab) and also added jars in the build path of the Your Project under project>properties>Build Path.
    2. In case you have a DC instead of Web Dynpro Project then you have to add the com.sap.security.api under Your DC>Used DCs and have compile time and runtime dependency added.
    Here java.lang.NoClassDefFoundError is caused basically due to only build time dependency added and reference to the jar missing at runtime. Rest the code to retrieve the current user id using UME API and getUserByLogOnID("....") method with/without portal environment would not be an issue at all.
    Regards,
    Tushar SInha

  • Report Engine SDK - Rbean usage in standalone java application

    Post Author: Berndb
    CA Forum: JAVA
    In BOXI the rebean sdk is available in the Report Engine SDK.
    I remember that in the 6.5 world one could use RBEAN interface in a standalone java application.
    Is this still possible in BOXI R2?
    If yes can you supply a sample classpath which shows all libraries that needs to be assigned.
    Thanks in advance.
    bernd

    Post Author: datahog
    CA Forum: JAVA
    Ted's right, but for fun, take what you need from:
    <installation drive>:\Program Files\Business Objects\Tomcat\webapps\businessobjects\enterprise115\desktoplaunch\WEB-INF\lib
    and de-reference what's not needed when your project's done, but be careful.
    I've actually done some standalone Swing-based webi report renderers using https://xhtmlrenderer.dev.java.net/ + docHTMLView.getStringpart + TagSoup

  • Reading a XML file in a standalone java application

    Hi,
    What are my options if I have a standalone java application running outside any app. server and I need to read an XML file, probably read some of the attributes in the file...? Please explain clearly as I'm new to this. Appreciate your help.
    Thanks,
    Mahdad

    nope you don't need a DTD
    you have to write your Java code in a way that doesn't rely too much on the structure:
    - avoid getFirstChild().getFirstChild()... because you know that this element is first grandson of that element)
    - prefer using getElementByTagName() or some XPath() API
    but if the XML completely changes, well, yeah, you have to do some programmation: better think well your document structure in the beginning.

  • What should be done in certmap.conf for 2-way SSL support from a standalone Java application to an SSL enabled LDAP Server

    To support certficate based client authentication using 2-way SSL from a standalone java application which uses JNDI and JSSE1.0.2 to connect to an SSL enabled LDAP Server how do we configure the certmap.conf?Is there any additional setup required at the LDAP Server side apart from enablinf SSL with the option"Required Client Authentication" enabled.The 2 way SSL handshake goes through but the access log file (After configuring the certmap.conf for the issuer DN of the client certficate etc..)shows SSL failed to LDAP DN?But inspite of this access log error the Java client does get an SSL Connection object with which it is able to connect to the LDAP.IS the certmap.conf file being looked up by the LDAP Server at all?

    have you out.flush() and out.close() before you call connection.getInputStream()?

  • Rich-client Java application that is client to WLS6.1 but behind corporate proxy server

    We have a rich-client Java application that is a client to WLS6.1 that can't
    connect to the WLS6.1 server when the client is behind a corporate proxy
    server. What is a remedy for this?
    Thanks,
    Jim Weavere

    Found solution. Followed Part 2 of the solution as explained in http://support.bea.com/application?namespace=askbea&origin=ask_bea_answer.jsp&event=link.view_answer_page_solution&answerpage=solution&page=wlw/S-19283.htm
    What surprises me is that this solution to a common problem is hidden and hard
    to find. If I am correct, no part of WLS 8.1 documentation suggests this. Rather
    the doc says, set the system properties for the standard JDK 1.4 network properties
    and it should work fine. If it is actually supposed to work like this, is it a
    bug then?
    "Naveen Kumar" <[email protected]> wrote:
    >
    Hi,
    I have a web application deployed on WebLogic server 8.1 sp1. And my
    server is
    behind a http proxy server. Now one of the components in the application
    makes
    a web service call to a service located external to the system, and it
    always
    throws "java.net.UnknownHostException". I have set the Java system properties
    http.proxyHost = my proxy server, http.proxySet = true and http.proxyPort
    = 80
    and it still does not help.
    If I try to evaluate the web service component as a stand alone client
    using WebLogic's
    webserviceclient.jar, everything works fine. I can't figure what I have
    to do
    to get this component working from within the WebLogic server. Can anybody
    provide
    me with inputs, comments or suggestions.
    Naveen.

  • Accessing JNDI from Standalone JAVA application

    Hi,
    I want to access the JNDI tree from my
    standalone java application. (ie I have
    one weblogic server contains all my ejbs and client - swing - application which accesses that. )
    Here I don't want to ship weblogic.jar
    file to the client with swing application
    because it is of ~ 20 MP.
    Any other way to specify the INITIAL_CONTEXT_FATORY class.
    My code is
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    env.put(Context.PROVIDER_URL, DTEConfig.PROVIDER_URL);
    But since I don't want to give the
    weblogic.jar bundle to my client, how he
    could manage this with out weblogic.jndi.WLInitialContextFactory
    with him to get the initialContext ?
    -Rajan Kumar

    You can strip out the jndi related classes from the weblogic.jar which can be distributed
    to the client installation. I don't think you will be violating any bea licensing
    policies with this.
    Rajan Kumar <[email protected]> wrote:
    Hi,
    I want to access the JNDI tree from my
    standalone java application. (ie I have
    one weblogic server contains all my ejbs and client - swing - application
    which accesses that. )
    Here I don't want to ship weblogic.jar
    file to the client with swing application
    because it is of ~ 20 MP.
    Any other way to specify the INITIAL_CONTEXT_FATORY class.
    My code is
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    env.put(Context.PROVIDER_URL, DTEConfig.PROVIDER_URL);
    But since I don't want to give the
    weblogic.jar bundle to my client, how he
    could manage this with out weblogic.jndi.WLInitialContextFactory
    with him to get the initialContext ?
    -Rajan Kumar

  • How to make a Java application that will change the client box's IP address

    HI how to make a Java application( that application would be run on the client ) that will change the client box's IP address ( IP address of itself )

    If you can do that through the command line, then use Runtime.getRuntime().exec(...) to execute your command.

  • Distributing an Application that calls Visual Studio built DLLs

    I have a LabVIEW application that calls a Visual Studio 2005 built DLL, that then calls functions from another Visual Studio built DLL. When trying to distribute this application it will execute perfectly well on all machines with Visual Studio installed, but on any machine that doesn't have Visual Studio installed, despite installing the Visual Studio Redistributable Package on the machine, I get the error message on attempting to run the application:- "Missing External Function 4575Interface.dllname of function):C in (sub VI that uses function).vi" for the 10+ VIs that use functions called from that dll.
    Any suggestions?

    Hi,
    You will need to manually add all of the DLLs you
    are calling into your LabVIEW project. Check in the folder
    "Dependencies" in your Project Explorer what external DLLs the VIs are
    using, then drag and drop those DLLs into your project. LabVIEW will
    not automatically include these external DLLs when you specify a build
    specification unless you explicitly tell it to do so. When you
    distribute the application using an executable, always explicitly
    select those DLLs as "Always Included". Finally, register these DLLs on
    the target machine by using Windows command: regsvr32.exe. I would recommend you to write a Windows batch file *.bat to ease the deployment process. 
    Another
    point to note is, the DLLs you will find in the folder "Dependencies"
    are the DLLs LabVIEW automatically recognized through what you are
    calling in your program. However if any of these DLLs is linking some
    other DLLs, LabVIEW will not be able to detect them on the build, so
    you will need to add the DLLs into your project manually for
    distribution.
    Hope this helps,
    Best regards,
    Mark M.
    Applications Engineer
    National Instruments UK & Ireland

  • Java application to call BOXI cluster report server

    Dear all,
    We have a BOXI 3.1 cluster consisting of 2 servers, says server1 and server2.
    Which server should the java application call to? server1 or server2? I don't realize there is BOXI cluster common hostname that can be resolved by DNS.
    If the application calls to server1, what if server1 is down?
    Many thanks

    For the Java version of the BusinessObjects Enterprise SDK starting with XI 3.x, CMS members and their "Name Server Port" are persisted by the SDK in the file %HOME%\.businessobjects\clusterinfo.1200.properties file.    This file is read when SessionMgr is instantiated.
    When logon method with a CMS member name/port is invoked, it's looked up to determine what cluster the member belongs to, as recorded in the properties file.  Then a random CMS member from that cluster is selected, and connection is attempted to that CMS Name Server.
    So regardless of what CMS name you enter for the logon, it should at least fail over to a live one.
    The only issue happens if there's no clusterinfo.1200.properties file (i.e., fresh install on the SDK machine) or not accessible (if the process has no rights to access that file).  Then you have to ensure the CMS name you enter is to a live one.    If it's a fresh install and there's sufficient file access, the initial contact with a live CMS Name Service will retrieve all CMS members, and the SDK will update teh properties file.
    So you shouldn't have to worry about which CMS name you specify.
    Sincerely,
    Ted Ueda

  • How to pack a standalone Java application

    Hi, all. I have a stand alone Java application which includs some classes and some properties files. Meanwhile, I'm using some libraries(in jar files) from 3rd party as library extension.
    When I developed my application in the IDE, I can run it from the IDE and it works fine.
    Now I want to run it out of the IDE, it always complains that is can't find the 3rd party classes. I have tried to modify the classpath to include the extension libraries but it goes no avail. What might be the problem?
    And normally, how will you pack the application to submit it to the end-users? How do you include the libraries from 3rd party without end-users' awareness?
    Thanks a lot!

    Put it in a jar, and use the classpath-setting in the jar manifest file.
    Or extract the 3rdparty libraries, and put everything in a big jar.
    Or provide a .bat-file and a shellscript that sets classpath temporarily.

  • Creating a standalone java application

    I am using a java editor called JTogether from TogetherSoft. I have devloped a java application in this. I want to be able to run this application on another machine which has no JDK or JRE installed. How can i run my application without installing the whole JDK or JRE on the target machine?

    Install a JRE on the other machine.
    You don't seriously want to compile to .exe, you just think you do.

  • How can I build an application that calls functions in a dll if the associated hardware is not present?

    I am trying to build an application that use the "Call Library Function" node to call functions in a dll.
    The dll was provided by a third-party and includes functions to drive an I2C communication board.
    The problem I have is that the dll does not not properly because the hardware is not present.
    Therefore when I load the VI a broken arrow is displayed and when I am not able to build the application.
    I will not be running the application on the PC where I build the application, therefore I want to be able to build the application on a remote PC that has not all the hardware installed. Once the application will be build it will be installed on the target PC that has all the hardware.
    How can I make the application builder to build the application event if the dll is not properly loaded? (the dll will be properly loaded on the target PC)
    I want to do this on LabView 5.1.1, any ideas?

    Some .dlls don't try to attach to the driver when loaded.
    I've worked with both and unfortuately, I've not figured out a way around this problem.
    You could possibly use the Conditional Disable structure around the dll calls so they would not be loaded unless you're in the runtime engine. But i've not tried this so I don't know for sure if it's possible.
    Anyone??
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

Maybe you are looking for