Question : connecting to a data source

Hi,

I tried connecting to the data source through the following code,

                                  ctx = new InitialContext();
              javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("my_dsource");
              java.sql.Connection conn = ds.getConnection();
              Statement stmt = conn.createStatement();

I created a datasource in the examples console. But it throws the following error,

javax.naming.NameNotFoundException: Unable to resolve 'my_dsource' Resolved ;
remaining name 'my_dsource'
        at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(Basic
NamingNode.java:924)
        at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.jav
a:230)

Could any one please let me know what could be the error.

thanks.

Answer : connecting to a data source

Ok .. open the config.xml file of your server in notepad and search for      <JDBCDataSource ..> or <JDBCTxDataSource ..> elements. Try to spot your Datasource and ensuer that the JNDIName attribute for it is indeed my_dsource.

If it is there  then do following.

1. shutdown server
2. take a backup of config.xml in case something goes wrong
3.  Remove this datasource element from the config.xml and save it
4. Reboot server
5. Create the datasource again.

If not there then the datasource has not been deployed

Random Solutions  
 
programming4us programming4us