Cassandra DB Connection Issue - java

I am unable to connect to Cassandra DB. I have tried with port number 9042 but it is throwing an exception given below
java.sql.SQLNonTransientConnectionException: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2097152000)!.
Due to that I am using port number 9160 for the same. But it is giving me below exception
[main] ERROR org.bigsql.cassandra2.jdbc.CassandraConnection - Impossible to connect to server Server Name : org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection timed out: connect
Please provide the solution on the same. Please see below code that I am using for connection.
URL="jdbc:cassandra://server name:9160/schema";
address =address;
user=Username;
pass=Password;
Class.forName("org.bigsql.cassandra2.jdbc.CassandraDriver");
conn = DriverManager.getConnection(URL,user,pass);

The URL is not correct you have a problem in this URL :
URL="jdbc:cassandra://server name:9160/schema";
Here is the syntax you should to follow :
jdbc:cassandra://host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[keyspace][?options]]
So for example :
URL="jdbc:cassandra://10.6.99.99:9160/dbname";
So in place of server name you should to specify the #IP of your database or the right host.
Second after the port number 9160/schema you should to specify the name of your database and not the schema.
Take a look at :
cassandra jdbc driver
cassandra jdbc
EDIT
As #Mark Rotteveel mention : ..Or the port is wrong, or the port isn't
open on the accessible IP address for that hostname
so make sure that this port is open on the accessible IP address for that host name.

Related

Play framework java connection is not available to sql server database

I'm stucked in a problem during connection from my java project (play framework ) to a sql server database in Azure.
In local enviroment the connection works fine.
Below parameter in my application.conf :
db.default {
url="jdbc:sqlserver://server-name.database.windows.net:1433;database=database-name"
encrypt=true
trustServerCertificate=false
hostNameInCertificate="*.database.windows.net"
loginTimeout=30
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
username="root"
password="RootPwd"
}
This is the error received:
ERROR o.h.e.jdbc.spi.SqlExceptionHelper HikariPool-1 - Connection is
not available, request timed out after 30006ms. ERROR
o.h.e.jdbc.spi.SqlExceptionHelper The TCP/IP connection to the host
par-sql-server.database.windows.net, port 1433 has failed. Error:
"par-sql-server.database.windows.net. Verify the connection
properties. Make sure that an instance of SQL Server is running on the
host and accepting TCP/IP connections at the port. Make sure that TCP
connections to the port are not blocked by a firewall.". ERROR
p.api.http.DefaultHttpErrorHandler
play.api.PlayException: Execution exception[[CompletionException:
org.hibernate.exception.JDBCConnectionException: Unable to acquire
JDBC Connection]]
at play.api.http.HttpErrorHandlerExceptions$.$anonfun$convertToPlayException$3(HttpErrorHandler.scala:388)
at scala.Option.getOrElse(Option.scala:201)
at play.api.http.HttpErrorHandlerExceptions$.convertToPlayException(HttpErrorHandler.scala:388)
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:373)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:264)
at play.core.server.AkkaHttp
I have already checked that tcp/ip port 1433 is correctly available for database, and my ip is correctly setted to avoid firewall.
Any suggestions?
thanks
Usually this error occurs when the database is not getting the connection within the default connectionTimeout property.
You can try to increase the value of connectionTimeout in Java config as below:
config.setConnectionTimeout(300000);
below is one of the sample config:
HikariConfig config = new HikariConfig();
config.setMaximumPoolSize(20);
config.setConnectionTimeout(300000);
config.setConnectionTimeout(120000);
config.setLeakDetectionThreshold(300000);
If possible let me know the steps to reproduce this issue so that I can fix it accordingly, also based on the information you've provided these blogs (Blog1, Blog2) will help you in establishing the connection

java.sql.SQLException: The application requester cannot establish the connection

I have written a java program to connect to AS400 DB. I am using jt400-6.4.jar to connect to DB.
DB Properties I am using:
as400_dbUrl=jdbc:as400://host/schema;translate binary=true
as400_dbUser=user
as400_dbPassword=pass
My program is not able to connect to DB server i am getting the below error.
2017-06-30 05:36:53 ERROR DBUtil:88 - Exception:
java.sql.SQLException: The application requester cannot establish the connection. (A remote host refused an attempted connect operation.)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:528)
at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConnection.java:3130)
at com.ibm.as400.access.AS400JDBCDriver.prepareConnection(AS400JDBCDriver.java:1360)
at com.ibm.as400.access.AS400JDBCDriver.initializeConnection(AS400JDBCDriver.java:1211)
at com.ibm.as400.access.AS400JDBCDriver.connect(AS400JDBCDriver.java:352)
at java.sql.DriverManager.getConnection(DriverManager.java:426)
at java.sql.DriverManager.getConnection(DriverManager.java:474)
I googled about this, not able to find the exact reason.
I think jt400.jar will use 8471 as the port to connect to DB. Please correct me if I am wrong regarding this port.
I am not able to ping the host. ping host is not returning any response.
I am able to telnet like telnet host. But I am not able to telnet the system like telnet host 8471
Your hlep will be highly appreciable. Kindly help.
try updating your DB property as:
Add <:port-number> after host
as400_dbUrl=jdbc:as400://host:port/schema;translate binary=true
Hope this solves your problem.

Can't connect to Sql Server database using JDBC

I'm trying to make a connection to an already existing database in SQL Server 2012n with Netbeans 8.
Using the connection wizard I select Sql Server 2012 and enter the credentials and fields.
However I get the message that a connection cannot be established.
You can see screenshots of the entered fields:
I also tried using "localhost" instead of "STIJN" this didn't work. I also tried with the default port "1433". Also didn't worked, however what port should this be? Where can I see what port I'm using? Maybe the error lies in the port, otherwise I wouldn't know where I made a mistake.
Go to your SQL Server configuration manager -> SQL server network configuration -> protocols for SQLEXPRESS -> TCP/IP (double click on it for properties).
On protocol page set enabled to Yes.
On IP Addresses page, scroll to bottom.
TCP Dynamic Ports: 54629
TCP Port: 1433
Apply and ok.
Make a connection with:
Host: localhost
Port: 1433
Your credentials
Instance field = blank.
This should work.

Database connection string for a remote database server named 'localhost'

I have a remote mysql database server setup on a machine myuniversity.edu and server is named 'localhost'. On it I have the database named 'MyDatabase'.
I want to connect it through Java.
The connection urls that I have tried are:
jdbc:mysql://myuniversity.edu/localhost
jdbc:mysql://myuniversity.edu/localhost/MyDatabase
jdbc:mysql://myuniversity.edu:3306/MyDatabase
but I get the `Connection refused: connect` exception.
Could someone please tell what the connection url should be in this case?
Not really sure if your machine name is myuniversity.edu, you can instead try the IP Address with the connection string, Localhost is the name for loopback network interface and accessible on that machine only. Also make sure if your default port for mysql (may be 3306) is open. With IP address your connection string would look like:
jdbc:mysql://192.168.0.123/MyDatabase
With IP and port it would be:
jdbc:mysql://192.168.0.123:3306/MyDatabase
(You need to replace your IP in the above string)
I'ts impossible to connect remotely without (IP) address
try this approach
if you want to connect it via internet :
OPEN CMD on your computer
in CMD write ping myuniversity.edu (for example ping google.com)
then you will get an ip address of the website and you can copy the ip
then try this approach :
Connection con;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://THE IP ADDRESS :3306/DatabaseName");
System.out.println("CONNECTED");
}catch(Exception ex)
{
System.out.println(ex.getMessage());
}
Ok so here's what I did to fix the issue:
In my.cnf file, I changed the bind-address from '127.0.0.1' to the
'host ipaddress'. This allows connecting to the remote mysql server
but would not allow access for any remote host trying to connect to
it.
To fix that, I added an entry in user table with host '%'. This allows remote hosts to connect to the database.
Now I can connect to the database with jdbc:mysql://serverIpAddress:3306/MyDatabase

(Enterprise GlassFish v3 build 11) Communication link problem (MySQL DB)

I get a communication link failure while application tries to establish a connection with DB.
[#|2010-04-08T20:09:57.825+0300|SEVERE|glassfish3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=24;_ThreadName=Thread-1;|Cannot connect to database server = com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.|#]
Precisely at this string:
Statement s = conn.createStatement();
where conn is defined as follows:
private static java.sql.Connection conn;
For this app I have set a connection pool with default parameters and currently it (app) uses both JPA and direct JDBC queries. Recreation of connection pool gave nothing, connection pool ping gave next message:
Ping Connection Pool for pool is Failed. Ping failed Exce
ption - Connection could not be allocated because: Communications lin
k failure%%%EOL%%%%%%EOL%%%The last packet sent successfully to the s
erver was 0 milliseconds ago. The driver has not received any packets
from the server. Please check the server.log for more details.%%%EOL
%%%Ping failed Exception - Connection could not be allocated because:
Communications link failure
and flushing the connection pool gave:
com.sun.enterprise.admin.cli.CommandException: remote failure: Failed to flush connection pool ...
However I can connect to the database from a terminal. Besides I have the same app working on my local machine with identical connection pool settings.
Any one has an idea on whats going on or how to solve the trouble?
Such problem could be if you have mysql server & glassfish server on the same host, and in mysql configuration you have option bind to some public address (for example 192.168.0.1 of eth0 interface) that normally successfully working with simple jdbc/jpa using user#localhost, but they don`t in a case of glassfish JTA, instead to bind to some of local address you getting link failure. As rule you could not bind to any local (localhost/127.0.0.1) addresses of such mysql host if public address presented.
Example:
my.cnf
bind-address = 127.0.0.1
bind-address = 192.168.0.1
127.0.0.1 - assign to lo interface
192.168.0.1 - assign to eth0 interface
It is glassfish-mysql bug.
Currently in order to use JTA, you should not bind mysql to such address. (remove "bind-address=192.168.0.1" from my.cnf). Or use user#192.168.0.1 what is less secure.
Besides I have the same app working on my local machine with identical connection pool settings.
Are you connecting to the same database? If yes, maybe check that you're using the same JDBC driver.
In my case I set :
URL : jdbc:mysql://10.81.35.66:3306/testDB
and
url : jdbc:mysql://10.81.31.76:3306/vectordb
both When setting values while creating connection pool in additional property part
on glass fish admin console .

Categories