Can't connect to postgres db with jdbc - java

Note: I'm calling the security service the problem service here, but I doubt I can connect to the DB with any service- security is just the first one that has to do it.
I'm trying to modify a java application to use postgres instead of oracle, I'm getting connection issues, and my logs are not helpful.
The database is on a remote server, but it is being accessed successfully by other applications. I can connect with the postgres client without issue.
Any ideas where I should look?
The errors:
from the service I'm calling:
2020-08-11 14:47:37 INFO AuthenticationService:32 - Rest Services - starting authentication...
2020-08-11 14:47:38 ERROR AuthenticationService:119 - GetUserInfo: trying to connect to the Rest Serrvice, attempt 1, HTTP Error Code: 500
2020-08-11 14:47:38 ERROR AuthenticationService:120 - Response message: Internal Server Error
2020-08-11 14:47:38 ERROR AuthenticationService:146 - Problem getting User Info: Problem getting User Info 500, message: Internal Server Error
2020-08-11 14:47:38 ERROR AuthenticationService:62 - Problem getting User Info: Problem getting User Info 500, message: Internal Server Error
From the underlying problem service:
2020-08-11 14:47:38 INFO SecurityService:67 - Rest Services - getUserInfo
2020-08-11 14:47:38 INFO SecurityService:87 - Getting User Info from DB...
2020-08-11 14:47:38 ERROR SecurityService:110 - Couldn't establish connection to Database
My context.xml for problem service (resource section is identical in both services):
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/PhoenixSecurity" docBase="PhoenixSecurity"
crossContext="true" reloadable="true" debug="1">
<Resource name="jdbc/CtsRest" auth="Container"
type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://CORRECT-IP:5432/phoenix"
username="validUser" password="validPassword" maxActive="100" maxIdle="100" maxWait="-1"/>
</Context>

In troubleshooting these sorts of problems check the following in order:
Can you connect to PostgreSQL from another machine on the LAN? If not, it may not be listening on the address?
Can you connect locally? Is it even running?
Now in the case where the second succeeds and the first fails, here are things to check in order:
listen_address in postgresql.conf
firewall rules
Anything in between that might interfere with the network connections.
*Sometimes when you pass localhost in the jdbc url this will be mapped to ipv6 address. Try specifying the the ip4 address explicitly.

Turns out my issue was assuming that the jdbc driver for postgres could create a connection the same way as the one for oracle. It can't. Lesson learned.

Related

Embedded Database project

So I received this error message:
java.sql.SQLNonTransientConnectionException: java.net.ConnectException
: Error connecting to server localhost on port
What does this even mean? I searched it up and what I found was that I never created an embedded database but rather a server? Regardless, the steps I followed were exact in order to create an embedded database.

Proxy error 502 aws after configuring .ebextensions

I've deployed my Java web application to a AWS server, but I get an 502 proxy error like this when making a get request:
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /product.
Reason: Error reading from remote server
The database connection works fine if the application is deployed locally with an online database.
I've tried to configure .ebextensions and my YAML file looks like these:
option_settings:
option_name: Timeout
value: 1000
This is my draft version of my site and you can see the error code: http://platformaruralpreno.eu-west-2.elasticbeanstalk.com/product

Oracle : Refuse Connection Listener Error

I try to connect Oracle database using Java.
I am receiving the following error:
Cannot create PoolableConnectionFactory (Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
I am sure that my Java code is fine since i succeeded to connect a PostgresDB earlier.
This is my context.xml :
<Resource name="jdbc/TestDB"
auth="Container"
type="javax.sql.DataSource"
username="admin"
password="password"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#xx.xx.xxx.xxx:1521:cuat/"/>
Maybe my connecting URL is in a wrong format. Thanks in advance.
If I remember correctly, Oracle makes a distinction between service names and SID-s (identifiers). You may try
url="jdbc:oracle:thin:#xx.xx.xx.xx:1521/cuat" (if cuat is a service name, rather than a SID, use / , not :)
Anyway, check the tnsnames.ora file.
The URL looks correct. The error you are receiving is that the tns listener on your machine (look for a file called tnsnames.ora) is not completely up to date with your database. Refresh this file and the connection should work.
The listener isn't servicing a database SID or SERVICE named 'cuat'
Check the listener and make sure you've got the name right.
On the server you can run "lsnrctl status" for a list of services.

how can we add a document using solr cloud server

While adding a document using solr cloud server I'm getting following exception
60 [main] INFO org.apache.solr.common.cloud.ConnectionManager - Waiting for client to connect to ZooKeeper
65 [main-SendThread(jmajeed.ibsorb.com:8982)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server jmajeed.ibsorb.com/192.168.70.91:8982. Will not attempt to authenticate using SASL (unknown error)
69 [main-SendThread(jmajeed.ibsorb.com:8982)] INFO org.apache.zookeeper.ClientCnxn - Socket connection established to jmajeed.ibsorb.com/192.168.70.91:8982, initiating session
Exception in thread "main" java.lang.RuntimeException: java.util.concurrent.TimeoutException: Could not connect to ZooKeeper 192.168.70.91:8982/#/hotelcontent within 10000 ms
Does anybody has any idea why this is happening??
Thanks.
Have the disturbed the default configuration of solr nodes because by default if you do not specify the port the first node in the cluster will start in 8983 port so check this first. If this is not the problem then check whether the cluster is up or not by accessing admin UI of solr cloud. Then see whether all the shards in the cluster are alive by clicking on the cloud tab.
If everything is fine and still you are facing the above problem then are you trying to access a remote solr cloud server and it is firewall issue.

Unable to get connection, DataSource invalid - Netbeans, MySQL

I'm following the tutorial of Netbeans site:
https://netbeans.org/kb/docs/web/mysql-webapp.html
everything was working fine until this step: Implementing JSTL code STEP 4 where the list should be displayed I get the following error:
javax.servlet.ServletException: javax.servlet.jsp.JspException:
Unable to get connection, DataSource invalid: "java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused."
root cause
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException :
Error connecting to server localhost on port 1527 with message Connection refused."
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.0 logs.
I suppose netbeans still tries to connect to the Derby DB. How can i change it to MySQL DB?
I am using Java EE7, MySQL, Netbeans, Glassfish 4
The stack trace indicates that the MySQL DB is not running on port 1527
See https://netbeans.org/kb/docs/ide/mysql.html
Use GlassFish Server Open Source Edition 3.x and Java EE Version 5 or 6
Then it works.
I had a similar problem and I solved it using a different approach. I changed the settings in the glassfish-web.xml file found in IFPWAFCAD/WebPages/WEB-INF folder. The following settings worked for me for this particular tutorial https://netbeans.org/kb/docs/web/mysql-webapp.html:
Resource Reference name: jdbc/IFPWAFCAD
JNDI Name: jdbc/IFPWAFCAD
Principal Name: root
Principal Password: nbuser
These settings will work for this particular tutorial - I used glassfish 4 - and Java EE 5. No need to install glassfish 3

Categories

Resources