Datasources connection questions

hi all
my question is about How the connections stored in a Jndi server datasource pool are managed.
For example, I'm developing a J2EE application with Ejbs and Datasources, etc. I saw that when I want to retrieve a connection from datasource to work on it I need do something like this:
For example to retrieve a datasource connection:
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,...);
jndiProps.put(Context.PROVIDER_URL, ...);
Context context = new InitialContext(jndiProps);
DataSource ds = (DataSource) context.lookup("jdbc/MyDatasource");
Connection con = ds.getConnection();
...I know in this case that the server manages a datasource connection pool, etc
My question is when a get a connection from the Datasource pool of my app server. do I need to release the connection with some special method when I finish with it (in order to return it to the pool) or it doesn't matter ?
thanks in advance

If I have three prepared statements right in a row with nothing in between should I close the connection after each one and then get it again?
Seems like I would be just as well off to just get the conn once do the 3 things then close it.
and in spots I might actually be doing something as i step through the first result set so can i use conn.preparedStatement() in the loop many times without getting the connection and closing each time through the loop?
i of course close all PS and RS and use diff PS2 and RS2 in the loop so i 'm just talking about keeping the conn open while (RS.next()) and use it multiple times to conn.preparedStatement() inside the loop?
or should i use 2 connections lol and open conn1 and then in loop use conn2 and close it each time around the loop and then close conn1 when i exit the loop?

Similar Messages

  • DataSource & Connection pools

    Hi,
    I have a couple of question about DataSources and connection pools.
    1. Are DataSources & connection pools the same thing?
    2. Typically the data-sources.xml file, shows in plain text a user/name password combination. Isn't this a security risk? Can anything be done about this?
    thanks in advance,
    Kevin

    Hi Kevin --
    1. Are DataSources & connection pools the same thing?
    A DataSource enables the clean abstraction of the database connection details from the code.
    A DataSource has a name, and it provides you with access to connections via some configuration information it has (ie database host, port, sid, username/password). To get a connection, you first locate the datasource, and then ask it for a connection.
    Since the DataSource is now providing access to connections, you can get different types of DataSources that give you different behaviour. One example of this is a DataSource which supports connection pooling -- it will pool the connections for you. Some other datasources will support the use of container-managed-connections, which are used by EJB containers to support CMT.
    So while a DataSource can support connection pooling, the two are not synonomous.
    2. Typically the data-sources.xml file, shows in plain text a user/name password combination. Isn't this a security risk? Can anything be done about this?
    In the current production version and prior, the data-sources.xml file stored details in clear-text. Besides ensuring that the file has the correct level of OS priviliges set on it to ensure it can't be easily viewed, the only other workaround was to specify the username/password as parameters to the ds.getConnection() method. This puts the username/password back into the code so it breaks the concept of clean abstraction, but it was an option to avoid it being in the xml file.
    In our 904 release (available as a dev preview now on OTN) we support the use of password indirection for the passwords in this file. This enables you to specify a logcal name for a password, then create the actual user/password combination in our encrypted JAZN user repository. When the datasource is used, the container follows the indirection and retrives the password from the encrypted storage area.
    I'm pretty sure this is documented in the beta version of 904 J2EE Services Guide, see
    http://otn.oracle.com/tech/java/oc4j/904/doc_library/services-904-preview.pdf
    cheers
    -steve-

  • Test SSRS DataSource Connection Programtically

    Hi, Dear
    I have created a SSRS Datasource programatically.
    I also would like to Test this SSRS Datasource Connection programatically.
    But it seems no API to do that.
    Is there a way to do it programatically?
    Regards
    Ming

    Hi Jiulidaji,
    According to your description, you want to test the SSRS Data Source Connection programmatically. Right?
    In program design, generally we create a separated class/function for database connection. If we want to test the connection, we just need to test this class/function only. For testing the connection, we can directly output/print the
    connection object, if it can return a hash code string which means we connect the data source successfully. If the connection is failure, it will return null value when printing the connection object.
    If you still have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • Loosing datasource connection in a server thread

    Hi,
    In a backing bean I start a long term thread that uses the datasource connection taken from application module.
    Everything works fine but after a period of time between one and two hours the connection is lost and server throws a
    <BEA-001112> <Test "SELECT 1 FROM DUAL" set up for pool "AEE2010DS" failed with exception: "java.sql.SQLException: Connection Closed".>
    Is there any way to stop the server from closing the connection that is used in a separate thread, programmatically or using configuration?
    Any comment will be helpful,
    Thanks

    That looks like something external is killing the connection, either the DBMS or a firewall.

  • Error !! Cannot fetch a datasource connection

    I am a beginner in Oracle BPEL process Manager,
    i am experiencing the following error :
    After starting the BPEL PM server, i got the following in the Dos Window:
    " Message Handle error:
    An exception occurred while attempting to process the message "com.collaxa.cube.engine.dispatch.message.process.SetDbDefaultMessage."the exception is tranaction was rolledback........"
    then i tried also to open the BPEL console and i logged in , but i got
    "Cannot fetch a datasource connectionThe process domain was unable to establish a connection with the datasource with the connection URL "jdbc/BPELServerDataSource". The exception reported is: Internal Error:Invalid Connect String
    Please check that the machine hosting the datasource is physically connected to the network. Otherwise, check that the datasource connection parameters (user/password) is currently valid."
    What could be wrong !
    Please Help.
    Thanks in advance

    Hey Rana,
    in OC4J_BPEL container, that is located under $AS_HOME/j2ee go to the config directory and open data-sources.xml.
    it seems during installation you might have provided wrong information..
    could you pls paste it here, that we can figure out what's wrong..
    in what enviroment did this occur,
    thx clemens

  • EnvironmentException: -600: Could not retrieve a datasource connection

    Hi,
    I am getting below errors in my logs has anybody have any idea about below errors.
    0.4 IJFWK-302 itseelm-lx4065.xxx.com 2013-02-12 05:55:40 EBCCOP01 971 NA BsGetDeliveryMethods irwuser irwuser EBCCOM01 28442421A3EF52E9C8692AA9F19FFC42 37 <?xml version="1.0" encoding="UTF-8"?> <SystemError><Message>-302: Error caught while executing the business task. Marked transaction for rollback; nested exception is: com.xxx.xxxx1.util.exception.EnvironmentException: -600: Could not retrieve a datasource connection for user 'null'.; nested exception is: com.ibm.websphere.ce.cm.StaleConnectionException: The Network Adapter could not establish the connectionDSRA0010E: SQL State = 61000, Error Code = 20</Messa
    Thanks
    Edited by: Ramstimo on 15 Feb, 2013 9:34 AM
    Edited by: Ramstimo on 15 Feb, 2013 9:36 AM

    Hi,
    Can you paste the jdbc connection that you have used in your application code here?
    Regards,
    Kishore

  • Script for checking datasource connections

    Hi,
    I would like to find out if it's possible to monitor datasource connections using Unix based scripts and if so how can this be accomplished?
    Thank you in advance
    Twaggz

    Hi
    Thanks for the link however I was looking at enabling monitoring at an AIX level.

  • SSRS 2005 change datasource / Connection String

    Hi All
    I need to change the some shared data source on ssrs 2005 for the migration of some dbs.
    Can I do it on tsql, I need to update the datasource / Connection String only for the reports that uses it.
    How to change it on table : [ReportServer].[dbo].[DataSource] table. ?
    Thanks a lot in advance.

    It is not recommended to update records directly in Catalog table.
    You can try
    programmatic way to update that.
    SSRS is webservice so you have to use something like below.
    https://<<Report Server Name>>/ReportServer/ReportService2005.asmx
    Make sure you do BACKUP database before doing any changes.
    Regards,
    Vishal Patel
    Blog: http://vspatel.co.uk
    Site: http://lehrity.com

  • Infosource and datasource connection

    Hi Experts,
    In the BI 3.5 business content, what is the best way to decide which datasource connects to which infosource? For example if i were to install BI content for SD i have about 8 datasources and 20 infosources and 6 cubes only.
    How can i setup a dataflow based on Bi content only?
    Should i make a decision based on the fields i am interested in? Please educate me on this.
    Thanks
    K

    Hi Krishna,
    Go to RSA1--->, right mouse show data flow you can double click the elements.
    On the Source systems you can see the relation between DS and IS.
    Also try table RSOLTPSOURCE - field OLTPSOURCE for datasource,field BASOSOURCE for infosource.using 'show data flow' as mentioned, click 'technical name on/off' to have the technical name displayed.
    hope this helps.
    Regards
    CSM Reddy

  • How to remove unused datasource connections in Report Builder 3

    In Report Builder 3.0 using a wizard to create a new Report, select create a DataSet. It opens a "Choose a connection to a datasource" dialog box. It shows previously used datasource connections of other ReportSevers I have accessed long
    time back. But I dont want to see datasource connection not in use. How can I remove those datasource connections used in past but they are still available in the list.  

    Hi Saty
    You can find more information about Remove previously used datasource connections.
    http://connect.microsoft.com/SQLServer/feedback/details/679232/cannot-remove-old-unusable-data-source-connections-from-report-builder-3-0-wizard-dialog
    SUHAS http://suhaskudekar.blogspot.com/ Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful.

  • ADF BC  in ADF Swing application(global datasource connection)

    Hi all!
    I have ADF-Swing based application.
    I have a standalone Weblogic server and global datasource (for example, name of datasource hrGlobal)
    I want to use this datasource(hrGlobal) in my application module. All my entities and views must connect into the database, using this datasource.
    The question is, how can I declare this remote connection in connections.xml, for using him in Application Module?
    In forum or in documentation a can't find the answer for this question. So, any help is welcome:)
    Thank you all for responses.
    PS. JDeveloper version is 11.1.1.3
    WLS version is 10.3.3

    Thank you for links. Also, I found very useful link http://suns1988.blogspot.com/2011/02/adf-desktop-application.html
    So, I had deployed application on WLS. Ear size is 95 MB with folder adfjars, that includes many jar libraries.
    Now I'm trying to run WebStart file, but get an error "com.sun.deploy.net.JARSigningException: Found unsigned entry in resource: http://myurl:myport/testWebStart/adfjars/xmlparserv2.jar".
    Can you help me, please?
    And the 2-d question is about libraries in folder "adfjars": Can I share this libraries on WLS, than not to deploy each time in Ear archive?
    Edited by: Stanislav on 01.05.2011 7:17

  • Database connection question...

    i am using Java 1.5.0_06 and to connect to MySQL database i use Connector/J and the following code:
    try {
    Class.forName("com.mysql.jdbc.Driver");
    } catch(java.lang.ClassNotFoundException e) {
    System.err.print("Main: ClassNotFoundException: ");
    System.err.println(e.getMessage());
    return;
    try {
    con = DriverManager.getConnection(dburl);
    ps = con.prepareStatement(
    I was told i should be using a DataSource to do connection pooling and i have read over the info and downloaded jdbc2_0-stdext.jar and i am using MySQL and windows XP pro.
    the code looks like this
    Context ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("jdbc/InventoryDB");
    Connection con = ds.getConnection("myUserName", "myPassword");
    then i just use con as i have already in my code.
    Can someone please point me in the right direction to get this working.
    I read this:
    A systems administrator or someone working in that capacity deploys a DataSource object. Deployment, which involves setting the DataSource object's properties and then registering it with a JNDI naming service, is generally done with a tool. As part of the registration process, the systems administrator will associate the DataSource object with a logical name. This name can be almost anything, usually being a name that describes the data source and that is easy to remember. In the example that follows, the logical name for the data source is InventoryDB . By convention, logical names for DataSource objects are in the subcontext jdbc , so the full logical name in this example is jdbc/InventoryDB .
    i have goggled but can't seem to find out exactly what i need to do next.
    I can't find the "tool" and have to be honest i am lost lol.
    can the The JDBC 2.0 Optional Package work with Java 1.5.0_06?

    i am using Java 1.5.0_06 and to connect to MySQL database i use Connector/J and the following code: i updated it to use manual connection pooling like so:
    final String dburl = "jdbc:mysql://localhost/......";
    Connection con = null;
    try {
    Class.forName("com.mysql.jdbc.Driver");
    } catch(java.lang.ClassNotFoundException e) {
    System.err.print("Main: ClassNotFoundException: ");
    System.err.println(e.getMessage());
    return;
    try {
    DataSource dataSource = setupDataSource(dburl);
    con = dataSource.getConnection();
    con.close();
    public static DataSource setupDataSource(String connectURI) {
    ObjectPool connectionPool = new GenericObjectPool(null);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
    return dataSource;
    so i compiled and ran it and it worked no problem but my question is that this is a server that does some db work upon starting and then waits for clients like so:
    while (listening)
         new PSMultiServerThread(serverSocket.accept()).start();
    so once i am in PSMultiServerThread what exactly do i need to do?
    i know i don't need to do this again:
    Class.forName("com.mysql.jdbc.Driver");
    but do i need to do this again:
    DataSource dataSource = setupDataSource(dburl);
    i geuss i have to to declare the variable lol.
    and do i include this code in the PSMultiServerThread
    public static DataSource setupDataSource(String connectURI) {
    ObjectPool connectionPool = new GenericObjectPool(null);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
    return dataSource;
    --------------------------------------------------------------------------------------

  • DataSource Connection Pooling in 903?

    We are having difficulty getting 9iAS DataSource Pooling to work. We are using 9iAS 9.0.3 (without Infrastructure) and, as per the J2EE Services Guide, have :
    1) Added...
    Context ic = new InitialContext();
    DataSource ds (DataSource) ic.lookup("jdbc/OracleDS")
    Connection con = ds.getConnection();
    ...to our code.
    2) Modified the default DataSource's url, username, password, min-connections & max-connections from within Enterprise Manager (leaving ejb-location as is at "jdbc/OracleDS") and restarted the Instance.
    The app generates an exception when trying to locate the OracleDS, however.
    We have also tried replacing the "com.evermind.sql.DriverManagerDataSource" class with "oracle.jdbc.pool.OracleConnectionCacheImpl" as per another post's recommendation.
    It appears that others have had similar problems (prior to 903?), but many have, in fact, (now) got this working successfully -- what are we missing please......?
    Thanks.

    Hi people!
    I have a question on the above code.
    I tried it myself on OC4j 9.0.3 (the one that comes with JDeveloper) and I noticed the connections on the pool. The problem is the behaviour of this code when the datasource is configured to have as a "max_connections" attribute a value less than 10, e.g. 8.
    I tried a datasource of the following form
         <data-source
              class="com.evermind.sql.DriverManagerDataSource"
              name="OracleDS"
              location="jdbc/OracleCoreDS"
              xa-location="jdbc/xa/OracleXADS"
              ejb-location="jdbc/OracleDS"
              connection-driver="oracle.jdbc.driver.OracleDriver"
              username="myuser"
              password="mypass"
              min-connections="2"
              max-connections="8"
              url="jdbc:oracle:thin:@localhost:1521:orcl"
              inactivity-timeout="60">
         <property name="cacheScheme" value="DYNAMIC_SCHEME"/>
         </data-source>
    but the execution of the code stops when it comes to get a Statement object out of the 9th connection object. Isn't the pool supposed to give a new connection and remove it when it's finished with it? After all, the documentation says that this is the default behaviour of the pool (it is not necessary to declare the DYNAMIC_SCHEME in the data-source.xml)
    I am interested in this, because I have a bunch of JSP files (100 of them or even more) that shall use the same connection pool. If some of them are being executed concurrently, then there will definitely be a problem with the available connection objects.
    Thanx

  • DAO pattern datasource connection help

    After researching and attempting to implement the Data Access Object pattern using the Abstract Factory pattern I run into one problem for which I haven't found a solution.
    All of the solutions that I have found hardcode the database connection URL and user credentials into either the concrete DAO factory or the concrete DAO object iteself. However, in the application that I am working with, the user credentials will be entered on a login screen and passed into the business objects that reference the data access objects.
    My questions are:
    Which object should receive the user credentials and datasource URL to authorize the user? (The storage solution that I am using returns query results based on the user's security settings in the repository.)
    How do I abstract this connection information to ensure that if I swap in a different storage solution I won't have to change the business objects or the interface to the DAO factory/objects?

    Ideally, one should always use the concrete DAOFactory to get you the database specific connection. The reason being that the one concrete DAOFactory exist for one particular database, and creates/returns DAO objects specialized for firing SQLs to that database.
    So writing connection code should be removed from DAO classes and put in the factory class.
    Now, coming to your problem.
    The user credentials are supplied by the user. These credentials are passed on to your business objects that in turn invoke an operation on a particular DAO to fire a SQL and get back the ResultSet.
    The business objects would typically get hold of the AbstractFactory to get the concrete factory, and using the concrete factory handle, it would get the concrete DAO class.
    The DAO class in turn would use the concrete DAOFactory to get a connection, fire SQL, get the ResultSet and close/return the connection.
    So, the best place to handle your issue is to write a public static final method in your AbstractDAOFactory class that returns you a 'fully configured' concrete DAOFactory class. The right time to use your user supplied credentials is when the AbstractFactory is creating your concrete DAOFactory class.
    Why?
    Because, every new user would represent a new database connection to your database. And that new user is allowed to do host of things using the number of DAOs that you have. So, ideally, for every user the JDBC connection setup part should be re-configured.
    So, just have the AbstractFactory return you a re-configured concrete DAOFactory for every new user by passing this AbstractFactory 2 information:
    1. "whichDAOFactory" to return, and
    2. "ConfigVO" ValueObject having the UID/PWD.
    So extending the example given by Sun:
    public static DAOFactory getDAOFactory(int whichFactory, Object ConfigVO)
    switch (whichFactory)
    case CLOUDSCAPE:
    return new CloudscapeDAOFactory().configure(ConfigVO);
    So, just by adding an abstract method configure() in the AbstractDAOFactory class to force all the extending concrete class to define their own ways to configure themselve with the user supplied credentials.
    Regards

  • What happened when using non-TX datasource connection in a Transaction?

    Hi,
    I try to update a timestamp table in a transactional EJB method invocation.
    The table is in the same db where the entity bean stores. I get the
    connection via DataSource (non-transactional), and issue the sql statement,
    and then close the connection.
    My question is: is my update part of the EJB transaction? If yes, how do
    I manage to get the timestamp update out of the scope of the transaction
    since I just want to timestamp no matter wether the EJB transactional method
    invokcation succeed or fails. Do I need to explicitly suspend and resume
    the transaction?
    Thanks!
    -Chunbo

    Chunbo Huang wrote:
    >
    Hi,
    I try to update a timestamp table in a transactional EJB method invocation.
    The table is in the same db where the entity bean stores. I get the
    connection via DataSource (non-transactional), and issue the sql statement,
    and then close the connection.
    My question is: is my update part of the EJB transaction? If yes, how do
    I manage to get the timestamp update out of the scope of the transaction
    since I just want to timestamp no matter wether the EJB transactional method
    invokcation succeed or fails. Do I need to explicitly suspend and resume
    the transaction?Hi. Your update is non-transactional. It is not part of the EJB transaction,
    and will succeed or fail at the time you do it, regardless of the eventual
    fate of the EJB transaction.
    Joe
    >
    Thanks!
    -Chunbo

Maybe you are looking for

  • Query Degradation--Hash Join Degraded

    Hi All, I found one query degradation issue.I am on 10.2.0.3.0 (Sun OS) with optimizer_mode=ALL_ROWS. This is a dataware house db. All 3 tables involved are parition tables (with daily partitions).Partitions are created in advance and ELT jobs loads

  • Resizing and changing aspect ratio

    Ihave a photo of 5 ins by 4 ins. How can I make it 6 ins by 4 ins and keep the composition? CS6

  • Node organization : one or multi ?

    Hi. My organization runs OCS10G calendar on 5 nodes (one per location), for approx 3000 accounts, on the same Linux server (we have another server for OID, data are on a NetApp NAS). Several colleagues would like to merge the 5 nodes into a single on

  • Type "/TDM/9_600C00001" is unknown - TDMS ABAP Dump

    Good afternoon, I'm starting the data transfer phase in my TDMS package and I've run across the following error message. TDMS created all the reports it needs for data deletion in the receiver system, but all the reports have a syntax error causeing

  • Enhancement for creating IDOC.

    Hi All, I have a requirement in which I have to generate a IDOC of type INSPECTIONPLAN_CREATE01 everytime Inspection Plan is created(QP01), changed(QP02) or deleted. Can anyone suggest me the appropriate enhancement or BADI for the same. Regards, Mon