java.sql.SQLException encountered when connecting to Oracle database - java

I get the following error when I try to run my project:
java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169870080)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
Any ideas?

You're getting an ORA-12505 error ("TNS: listener could not resolve SID given in connection description."). This happens when the SID (System ID) of the database you wish to connect to isn't registered with Oracle's listener. If you can find the JDBC connection information, you may find something that matches this pattern:
jdbc:oracle:thin:[user]/[password]#[host]:[port]:[sid]
In this case, Oracle is telling you that [sid] does not exist on the server [host]. You may be connecting to the wrong server.

Connection refused means that the server is not allowing your client to connect. Double check the server settings and make sure your host is allowed to connect, at the very least.

Related

Unable to connect to a Oracle db from Linux machine in java

I have registered a Linux machine as runner in my gitlab and tried to execute my scripts there.
While executing I got an error for database connection
Issue : java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
When I connect from my local machine (Windows 7 & 10) it is working fine.
Attempts:
Tried to connect using jtds but I'm getting some other unknown issue.
Checked few other answers and they have provided that it could be because of firewall enabled but since we did not have full access to that db server , I could not disable and check.(Could this be the issue?)
My Connection code :
ConURL = "jdbc:oracle:thin:#" + ConstructSQLConnectionURL(host,sid,port);
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(ConURL, dbUserName, dbPassword);
I am stuck with this issue and blocked from executing pipeline.
Can anyone let me know what could be the possible reason for this and help me with this?
Thanks in advance
It appears to be a network connectivity issue. I'd start with local firewalls on each system. Can you ping the database from the client? If not, look for network routing or firewall blockers. Also look at host-based firewalls, or confirm with the DBA whether there is something like valid node checking in place to limit database clients.

SQL eRROR :Cannot load connection class because of underlying exception:

I don't know why this is happening error
I'm trying to simply connect my database to jdbc
In the url jdbc:mysel://localhost:test you set the host as localhost and the port as test
There is no such port called test, you need to provide a port number.
Most likely you are using the default port for mysql, so you might need to provide one at all.

Netbeans Connection to SQLSERVER still not wroking

I am still facing this problem for about 2 days already. It seems I did some researched on Google and as well stack overflow. I followed step by step but still not running.
-> Enable SQL BROWSER
-> Enable TCP/IP PORT and change to 1433
I tried both but still not working. It still giving me this error.
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host ., named instance sqlexpress has failed. Error: "java.net.UnknownHostException: .". Verify the server and instance names, check that no firewall is blocking UDP traffic to port 1434, and for SQL Server 2005 or later verify that the SQL Server Browser Service is running on the host.
This is my connection code:
Connection conn = DriverManager.getConnection("jdbc:sqlserver://.\\sqlexpress;user=sa;password=;database=pharmacy_posic");
My server name: .\sqlexpress
My Username : sa
My password : (blank)
Am I making any mistake on the connection?
Check this it is explained very well:
https://www.youtube.com/watch?v=Z46OHxdEEEI

CAn't connect to Oracle with Spring Boot and Hibernate

I have a working Spring Boot app (1.2) that uses Postgres. Today I am trying to switch it to Oracle, but when I try to connect I get an exception that says:
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
And below that,
Caused by: java.net.ConnectException: Connection refused
So of course that looks like bad credentials, but I know they are good, and they are working in Oracle SQL Developer just fine. I'm baffled. Here are my properties file entries:
# Properties for Hibernate and Oracle
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:#//earth-db-11:5121/stardev
spring.datasource.username=ops$abcdefg
spring.datasource.password=mypassword
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
The only idea I have is that there is a $ in the user name, and I have tried escaping it and putting double quotes around it.
Any ideas?
Thanks...
UPDATE:
Many thanks to BonanzaOne, I did have the port number wrong. Correcting that results in a new error:
java.sql.SQLRecoverableException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
I looked it up of course, but I don't follow what its telling me:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Cause: The listener received a request to establish a connection to a database
or other service. The connect descriptor received by the listener specified a
service name for a service (usually a database service) that either has not yet
dynamically registered with the listener or has not been statically configured
for the listener. This may be a temporary condition such as after the listener
has started, but before the database instance has registered with the listener.
Still, SQL Explorer connects fine.
That exception means that the Oracle listener is not up, or you are trying to connect to a listener that don't exist/not accessible.
My guess is that you trying the wrong port "5121". Oracle default port is 1521.
Can you try with that and see what happens?
From the FAQ there are basically two ways of composing your JDBC string URL:
Old syntax
jdbc:oracle:thin:#[HOST][:PORT]:SID
New syntax
jdbc:oracle:thin:#//[HOST][:PORT]/SERVICE
My guess is that you are using the wrong syntax-SID/Service name combination, in other words, you are using the new syntax that requires the SERVICE name, but you are using the SID name to do it.
Try this: jdbc:oracle:thin:#earth-db-11:1521:stardev
Or maybe find out the Service name and apply it to the new syntax that you are using, instead of the SID name.

Listener refused the connection with the following error: ORA-12514

I am trying to connect to an Oracle Database using java and JDBC code. I can't do that because I get the error below:
java.sql.SQLException: Listener refused the connection with the
following error: ORA-12514, TNS:listener does not currently know of
service requested in connect descriptor
What is the reason for the error and how to fix it ?
PS-
Out of all the DBMS, Oracle express 11g seems to be the most complicated and difficult to use.
Is that really the case ?
Listener does not currently know of service requested in connect
descriptor
Self explainatory. You're requesting connection to a service or instance in a DB that the DB's listener does not know, so it says "I have no clue".
Check the way you installed your Oracle 11g express. Remember that the service name there is often "xe".
I resolve this issue by increasing RAM size of my Virtual machine because i installed oracle
in VM that require more memory. So this could be one reason for your problem.

Categories

Resources