I have a machine with CentOS and mysql server on it (let's call it 'Server'). And another(my desktop) machine with Debian (let's call it 'Desktop'). I tried to launch java program on Desktop machine. Application connects to Server's mysql database without any troubles.
When I finished development of this application (it's still works and connects to DB well) I tried to deploy this app to Server machine. I'v built it the app on the server and tried to launch, using database, which still hosted on Server machine. So now it seems to be local database for my application. But it fails during connection to DB using Server IP address or "localhost" or 127.0.0.1. I have only:
java.sql.SQLException: null, message from server: "Host '82.192.90.179' is not allowed to connect to this MySQL server".
In my.cnf file on Server I've set "bind-address=0.0.0.0".
PS:The most interesting thing, I do everything on server using ssh, and if I try to connect to database with "mysql" console tool, it connects OK either with -h82.192.90.179 and without -h option(seems to be localhost as a dafault)
To know it is permission issue try GRANT ALL ON . TO 'someuser'#%;
http://dev.mysql.com/doc/refman/4.1/en/grant.html
Then modify the above statement by replacing % with '82.192.90.179' should work.
If you feel difficult to connect JDBC means try using mysql workbench MySQL WORKBENCH
1.Make sure you have to host your server code to local server or public server
2.If you host Local Server means it will not work
3.Make sure your server is alive or not
DB_URL = "jdbc:mysql://localhost:portnumber/databasename"
eg.DB_URL = "jdbc:mysql://localhost:3306/cmes"
Maintain Your Session configuration like this in your server side in Web.xml
<session-config>
<session-timeout>-1</session-timeout>
</session-config>
Related
There are 3 machines:
local -> some remote server -> oracle db server (via ldap)
I want to set up datasource connection (in my spring boot app) to the oracle db.
There is no direct connectivity between local machine and the one with oracle db.
So, i'm using the ssh tunnel through remote server:
ssh -L 127.0.0.1:8081:some.ldap.host:389 user#remote.server.host
In application.yml file i'm using further url:
spring:
datasource:
url: jdbc:oracle:thin:#ldap://127.0.0.1:8081//srvcnm,cn=OracleContext,dc=yy,dc=xx,dc=com
And when my app trying to get db connection, im getting the following error:
Caused by: oracle.net.nt.TimeoutInterruptHandler$IOReadTimeoutException: Socket read timed out
at oracle.net.nt.TimeoutSocketChannel.handleInterrupt(TimeoutSocketChannel.java:254)
at oracle.net.nt.TimeoutSocketChannel.connect(TimeoutSocketChannel.java:103)
at oracle.net.nt.TimeoutSocketChannel.<init>(TimeoutSocketChannel.java:77)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:192)
... 126 common frames omitted
Whenever i'm deploying app on the remote server and enter "direct" url in application.yml the connection is being obtained without any timeouts, and the app works well.
jdbc:oracle:thin:#ldap://some.ldap.host:389//srvcnm,cn=OracleContext,dc=yy,dc=xx,dc=com
Does anyone know how to handle this? How to get connection from local machine?
I may do some thing like this, I am going to create file call ~/.ssh/config then add following
Host remoteserver1
User usermane
Hostname ip or host name
ForwardAgent yes
Host oracleserver
User username
Hostname some.ldap.host
Port 22
# ForwardAgent yes if you need to forward one more instance
LocalForward 8081 some.ldap.host:389
ProxyCommand ssh -q -W %h:%p remoteserver1
What this does is that when I attempt to connect to ssh oracleserver from remoteserver1, it connects to hopper and then proxies the SSH connection to port 22 on overthere (ie: SSH on oracleserver).
now to connect via ssh do following ssh oracleserver , as it will make ssh tunnel between your machine and oracleserver via remoteserver1. along with port forwarding.
The problem was in redirecting source connection request to another machine with oracle db itself (after ldap auth).
So, the request's path looked like:
1.local -> 2.remote server -> 3.ldap server -> 4.oracle db server
There wasn't connectivity between 1st and 4th machine as the tunnel was only between 1th and 3rd one.
So, you if you faced this issue, you may add one more ssh tunnel (First tunnel is for ldap server, second one for oracle db) and enrich your "etc/hosts" with oracle server's routing.
In my case the issue was in access restrictions. The oracle server is filtering sockets somehow and grants access to certain machines.
Hi I am trying to connect to a local Postgres Db running in Virtualbox Centos, which connects through SSL tunnel. Example of how I connect via DBeaver is below.
DBeaver I am using a SSL tunnel tab and
I am using a pem file, and user and password
Postgres local connection
The Virtualbox is set to forward port as follows
Postgres Virtualbox port forward
My Java code without ssl tunnel is this
DriverManager.getConnection("jdbc:postgresql://localhost:5432/dbName?user=postgresuser&password=givepassword");
This is failing saying pg_hba.conf not found etc or if I give ssl=true in connection string , says its not supported.. How do I connect to Local DB using ssl tunnel?
[ My assumption in that pg_hba.conf file would be available on the Virtualbox Host Vm only.]
You may try using jsch which is an implementation of SSH in Java.
Here is a complete example of how to do it https://cryptofreek.org/2012/06/06/howto-jdbc-over-an-ssh-tunnel/
Note that in this case all your traffic will go to the proxy hence you need to close the session after reading/writting to the database.
I have a code which runs fine on the machine, where i have installed the database.
I am trying to run this code from other machine, which connects to the machine where MySQL is installed and tries to update data. However this code is not working from other machine.
i am trying to connect as follows.
ds = new BasicDataSource();
ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setUrl("jdbc:mysql://192.168.0.104:3306/sd_mmm_data");
ds.setUsername("<UserName>");
ds.setPassword("<PassCode>");
ds.setMaxIdle(1);
ds.setMaxWaitMillis(40000);
I have replaced the localhost with the corresponding IP. However when i run the code, i always get the error table not found.
I have created a new user which can connect from other machines and the user has all of the required privileges. i have tried connecting from cmd prompt on client system and the connection works as expected queries run as expected. i tried connecting from mysql WorkBench and the connection works from client system. but the connection doesn't work from Java code. What am i missing?
I have added an entry in client system hosts file as follows
ServerName
And i tried using the ServerName in place of IP address in java code. Even this didn't work.
I think you have to use grant the remote user which enables access for remote user.
GRANT ALL PRIVILEGES ON . TO 'USERNAME'#'1.2.3.4' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
Created new set of users. Flushed privileges but it didn't work.
Then went on with shutting down the database and tried restarting it. Even it didn't work. But tried fiddling with settings and tried creating new users and tried connecting, which finally worked. Don't exactly remember why it worked as i touched multiple network settings.
In one of my project, we are trying to connect to Postgres server via Java application. It gives an error when try to open connection. Stack trace is below -
{"timestamp":"2016-03-17T06:57:18.853Z",
"level":"ERROR",
"thread":"main",
"logger":"com.abc.messaging.status.configuration.ValidateDatabaseConfiguration",
"message":"Failed to initialize data source: \n
### Error opening session. Cause: java.lang.NullPointerException\n
### Cause: java.lang.NullPointerException","context":"default"}
While we have tried following -
Ping db server from application server - it's successful
Telnet db server and port (from app server)- it's also successful
We also tried a simple python script that connects to postgre server. It also connects to db successfully.
We then moved back to our staging server and tried to connect production db server from there. This is also done successfully.
We tried connecting staging db server from production app server, which also we COULDN'T.
We are assuming that we don't have any issue in our application. This is because, from staging server, application can connect to both staging db and production db. There by, it must be some application server issue or something.
PostgreSQL version - Production - 9.4.5 Staging - 9.4.4
Java version - 1.8.31
Any kind of help would be much appreciated.
Thanks in advance.
I have build an application in java, application is one and will be used on 3 different systems,And therefore the database of that application must be online to keep all 3 applications with up to date database...
In starting I developed my application based on localhost (wampserver) and used database in "PhpMyAdmin", and hopefully application is fully developed and ready to run.. but the problem is online database connectivity!
I have uploaded my database on a Site in PhpMyAdmin and they provided below information:
and the for connecting my app to this DB is:
String url = "jdbc:mysql://fdb12.biz.nf:3306/";
String dbName = "1738412_wstore";
String driver = "com.mysql.jdbc.Driver";
String userName = "1738412_wstore";
String password = "Password";
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url+dbName,userName,password);
now when I run my application it shows below error:
I dont know what the problem is there, please help me out through this..
I faced the same issue and the following helped me to solve.
http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database-remotely
Hopefully, your hosting provider should have same type of cpanel to configure MySQL database for remote connections.
Check for firewall.
Check if mysql is running.
2 things you can try:
Install MySql client locally on your machine and connect like: mysql -h fdb12.biz.nf -u 1738412_wstore -P<password>
This should work before you try anything else.
Make sure you're using the right imports in your code. See [here][1].
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
I think your DB server doesn't allow remote connections.
Try hosting in:
http://www.freesqldatabase.com/freemysqldatabase/
It's free and allow remote DB connections.
Good Luck!!!
Considering the Biz.nf FAQ:
How can I connect to my MySQL/PostgreSQL database? What settings
should I use for my script/software?
MySQL/PosgreSQL database connection can be established with script/software hosted only on your
web hosting account (meaning no remote access is allowed due to
security reasons). The following settings are needed:
So, since biz.nf does not allow remote access, it will be difficult for you to interact with their MYSQL server for your application.
The best solution and the most simple is probably to find a new provider which will allow the remote access. Heroku.com works very well.
If you really want to use the biz.nf services, it will be more difficult.
It's not a script or credential problem.
Maybe you can (probably not), try to login by SSH to configure your server to enable remote access to your MYSQL database server.
From the free plan, you will not have any access to the online SSH tool and you will need to configure your domain for a SSH connection.
In SSH, and it probably will not work considering the FAQ, you could try to simply modify your /etc/mysql/my.cnf file by commenting the bind-address line wich by default only allows local access (127.0.0.1). Then, try to restart your MYSQL service with: a simple service mysql restart to verify if the remote connection works.
If the remote connection still doesn't work after this, the only way I can find for the moment (unless you completely change your hosting provider) would be to create a kind of API hosted directly on the server and your Java program could interacts with your services (In JSON, by example).