Today, one of the teams was facing the issue ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
. They were trying to connect to Oracle using Spring Boot JPA application and getting the exception at application boot up.
Team was able to successfully connect to Oracle using SQLDeveloper. But, when connecting to Oracle using Spring Boot JPA application it was failing to boot up.
Like most developers, we googled around to find the answers. The popular answer that you will get is as mentioned in this stackoverflow question. The answer suggests that you have to update tnsnames.ora
file and add your service to it.
I knew it is not the right answer as we are able to connect using SQL Developer.
So, I started looking into the Spring Data JPA configuration of the application. The configuration that was giving error is shown below.
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver spring.datasource.url=jdbc:oracle:thin:@//myhost:1521/efsdev spring.datasource.username=myuser spring.datasource.password=mypassword spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
In the above configuration, there is only one configuration property that could be possibly wrong — spring.datasource.url
.
So, I googled around to find the correct way to specify JDBC url for Oracle.
I learned that there are two ways you can specify JDBC string URL. The two ways are:
1) jdbc:oracle:thin:@[HOST][:PORT]:SID
2) jdbc:oracle:thin:@//[HOST][:PORT]/SERVICE
As you can see above, we are using the second way to specify the URL. According to second URL syntax, efsdev
is the service name.
Developers mentioned that efsdev
is the SID. So, we need to use the first URL.
After changing the configuration to the one mentioned below, application was successfully able to connect with Oracle.
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver spring.datasource.url=jdbc:oracle:thin:@myhost:1521:efsdev spring.datasource.username=myuser spring.datasource.password=mypassword spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
That’s it for this post. I hope this saves someone’s day.
Thank you for putting in the effort and documenting this.
Its work for me thanks
Hi There,
you literally saved my day.
there is one more issue, now after doing the above it says
“ORA-28009: connection as SYS should be as SYSDBA or SYSOPER”
this “sys” user of mine has sysdba permissions.
this there any other way to specify if the user is infact sysdba?
Thanks in advance.
Waiting for you answer.
Regards,
Hasnain.
Your note stills being a daysaver. Thank you for sharing.
Same issue but this didn’t help 😦
Same here
Thanks man , you saved my lot of time !