Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Help me! About DataSourceFactory

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I'm writing a standard application accessing DB2. I want to use DataSource to get database connection in my program. The following is my code:
import com.ibm.websphere.advanced.cm.factory.DataSourceFactory;
import ...
public class Test {
...

public DataSource getDataSource() {
DataSource ds = null;
try {
Properties props = new Properties();
props.setProperty(DataSourceFactory.NAME, "Test");
props.setProperty(DataSourceFactory.DATASOURCE_CLASS_NAME, "COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource");
props.setProperty(DataSourceFactory.DESCRIPTION, "Description");
props.setProperty(DataSourceFactory.USER, "db2admin");
props.setProperty(DataSourceFactory.PASSWORD, "password");
props.setProperty("databaseName", "sample");
ds = DataSourceFactory.getDataSource(props);
return ds;
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
The username and password are both correct. I compile my code with some websphere v4.0 libraries successfully, such as $WS_HOME/lib/ns.jar, $WS_HOME/lib/cm.jar, $WS_HOME/lib/iworb.jar, $WS_HOME/lib/j2ee.jar and db2java.zip. But an exception are thrown:
com.ibm.ejs.jts.jts.CurrentSet$InitializationError: not initialized
at com.ibm.ejs.jts.jts.CurrentSet.self(CurrentSet.java:218)
at com.ibm.ejs.jts.jts.CurrentSet.get_control(CurrentSet.java:265)
at com.ibm.ejs.jts.jts.Current.get_control(Current.java:72)
at com.ibm.ejs.util.tran.Util.getCoordinator(Util.java:13)
at com.ibm.ejs.cm.pool.ConnectionPool.allocateConnection(ConnectionPool.java:686)
at com.ibm.ejs.cm.pool.ConnectionPool.getConnection(ConnectionPool.java:312)
at com.ibm.ejs.cm.DataSourceImpl$1.run(DataSourceImpl.java:129)
at java.security.AccessController.doPrivileged(Native Method)
at com.ibm.ejs.cm.DataSourceImpl.getConnection(DataSourceImpl.java:127)
at ...
Could anyone help me to solve the problem? You could respond it in forum or send email to liming@cn.ibm.com. Your any advice will be appreciated. Thank you in advance.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
WAS provides GUI to configure datasource, which is linked to the dependant ejbs via the Depoyment Descriptior.
If you wnat just to use plain SQL managed directly by your application, get the java.sql.Connection having database name and credentials.
Regards
Leonard
 
Alan Lai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But my program is a stand-alone application, and it will run out of WebSphere server scope and have own JVM. So I have to create datasource object out of websphere with class com.ibm.websphere.advanced.cm.factory.DataSourceFactory. Otherwise, I found an example in "http://www-3.ibm.com/software/webservers/appserv/doc/v40/ae/infocenter/was/040204020101.html", but I couldn't run it correctly.
Would you like to give me some helpful advices? Thanks.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't use the DataSource Factory. It's not meant to be used that way. Don't do it. Follow the instructions of the previous poster -- define the Datasource in the admin console, and then look it up using JNDI. It doesn't matter that your process is standealone -- just make it an "application client" and start it using launchClient.bat and everything will be peachy.
Kyle
 
Alan Lai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But I got datasource with DataSourceFactory successfully when debugging my program in my IDE, which is Intellij IDEA 3.0.1. My runtime JVM was IBM JRE1.3 that I had copied from the installation directory of WebSphere v4.0 for Windows.


Otherwise, the program failed when it was runned on command line or other IDE(Eclipse2.0.1). The thrown exception was still the previous one. I am confused.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic