• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Problem while making oracle Data Source connection

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am making connection with Oracle DataSource and I am able connect with DB using first approach. But getting error using second approach. I want to use second approach. I want to make data connection in impl class.

First Approach

Second Approach:

Could you please guide me. Thanks in advance.
 
bablu singh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could anyone look into it?
 
Ranch Hand
Posts: 285
2
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I'm trying to help you but unable to trace the root cause just by seeing the above code as we also need to make very sure about all other  configurations. But I wish to suggest to debug the issue so that root cause can be found.

*. Make sure all the jars are in place.
*. Make sure your oracle connection can be established without any problem. You can use SQLDeveloper or some other tool to confirm.
*. Place a break point at one place from the stack trace pointed out code lines so that we can get to a point where NULL pointer exception can be thrown. With this program, I guess it's something to do with

getJdbcTemplate() {
       try {
             ..  }
           }

Please get back here if you get any clues by debugging.
 
Mohammed Sardar.
Ranch Hand
Posts: 285
2
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

bablu singh wrote:

First Approach



Please confirm with your connection URL has been specified completely like in the below format.  jdbc: oracle:thin:@localhost:9080:xe
 
bablu singh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mohammed, Thanks for looking into it.
As you suggested, all jars are in place, building using maven.
I checked the database connection with SQLDeveloper, its connecting properly.
Also, tried debugging and I am getting the error at line no 53. Please see the logs.
Connection URL is also valid and its in the jdbc: oracle:thin:@localhost:9080:xe format. Also, same is working using first approach, as I mentioned earlier.
 
Saloon Keeper
Posts: 28750
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is your "Datasource" class? If it's the standard J2EE one, those are not usually constructed in application code. For webapp servers, the DataSources are usually from a Database Connection Pool constructed by the appserver itself. For a stand-alone Spring application, I'd normally be constructing the DataSource connection factory in the spring configuration file. Often, in fact, the URL and credentials are injected in via something like LDAP in my apps.

 
bablu singh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using oracle jdbc pool datasource - oracle.jdbc.pool.OracleDataSource (ojdbc7-12.1.0.2.jar) and it's working properly using first approach. This Spring based application is not having any configuration XML file, Its purely a java based configuration. URL and credentials are configured in properties file. It's not using LDAP for authentication.
 
Tim Holloway
Saloon Keeper
Posts: 28750
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should display the JDBC URL actually being used just to make sure that the propery was read OK.

But your model URL appears to be missing the database ID. That is, you have:

jdbc:oracle:thin:@X.X.X.X:X:X

And you need something like:

jdbc:oracle:thin:@//dbhostname:1521/dbname

And if memory serves, "dbname" would be an Oracle TNS name, assuming that they are still using that concept. It was supposed to become something new back around Oracle 9, but last time anyone paid me to do Oracle, TNS names still worked.

Note that the "//" is NOT OPTIONAL. Slashes have very important meanings in URLs and URIs and the number of slashes denotes specific meaning as well.
 
bablu singh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You were right, its not pickin up the property file. URL value is coming as null, not only URL but username and password also. Then I tried:Its again giving me java.sql.SQLException: Invalid Oracle URL specified: OracleDataSource.makeURL error.Its giving me null pointer exception. Its not initializing appConfig by Autowiring. Could you please point me out where I am wrong.
 
Tim Holloway
Saloon Keeper
Posts: 28750
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This seems more like a Spring problem than an Oracle problem. I haven't used the strategy you're attempting, since most of my Spring apps were standard webapps, where LDAP allowed me to keep properties external to the WAR and thereby be able to use the same WAR for both development and production without rebuilding it. The properties approach is more appropriate to things like Spring Boot.

At this point, all I can do is recommend that you review how this feature works. Also, by default I see that the properties file should be named "application.properties" and it looks like it should be located in the root of the application's classes directory.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic