I just want to access the database in another system from current system. In that second system, i had already created a derby database which is in built in netbeans. I tried to access that database by changing the ip address instead of localhost in "jdbc:derby://localhost:1527/course".
But it shows java.net.ConnectException: Error connecting to server 10.6.3.3 on port 1527 with message connection timed out. How can i resolve this.. Please help me
You can run derby on two ways : embedded or server.
so first step is you need to run derby on server mode.However by running derby on server mode still only localhost can have access to database.
To give access to other IP's you need to run server with option : -h "0.0.0.0"
On windows : /pathtoderby/bin/startNetworkServer.bat -h "0.0.0.0"
On linux : /pathtoderby/bin/startNetworkServe.ksh =h "0.0.0.0"
Note: the reason you should not allow network access is security as derby is single user and plain text. before over network access make sure to read this topics to make sure you give secure access :
http://db.apache.org/derby/papers/DerbyTut/ns_intro.html
Related
I have a machine(A) that has access to the host running the Oracle listener. I can connect to it fine using SQL Developer.
I have another machine(B) that I would also like to make a connection to the same database but its doesn't have direct access to the host running the listener. However, it does have access to machine (A).
I would like to forward a port on machine A to the Oracle listener host which is listening on port 1521.
Then I should be able to make a database connection from machine B to machine A and then forward a port to the host that has the Oracle listener. Sort of a man in the middle.
However, I'm running into issues. I can't even connect to the Oracle database from machine B using the forwarded port. I have experience using ssh tunnels to do the same thing. In this case, I'm not using ssh and I don't understand why this will not work.
Below is the procedure I'm going through:
Log into machine B - Oracle client is installed. SQL Developer is installed.
Open SQL Developer - Select TNS connection. Enter in credentials. Connection Successful
TNS Names entry:
CRYSTAL=(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=yes)(FAILOVER=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=testhost.com)(PORT=1521)))(CONNECT_DATA=(service_name=svc1)))
Now setup forwarding:
C:\Windows\system32>netsh interface portproxy add v4tov4 listenaddress=127.0.0.1
listenport=1521 connectaddress=testhost.com connectport=1521
protocol=tcp
If I telnet localhost 1521 , it is able to make a connection.
As a simple test, I make sure I can connect on Machine B using SQL Developer. But this time, I set the connection type to advanced so I can enter the jdbc url.Note, I use 127.0.01 instead of testhost.com because it will be forwarded to testhost.com
jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=yes)(FAILOVER=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(service_name=svc1)))
This connection fails with "ORA-12516, TNS: listener could not find available handler with matching protocol stack"
I've checked for firewall issues and made sure port 1521 is open.
Any ideas what I might be missing or has anyone else had success forwarding a port to an Oracle listener?
Thanks to the comment from psaraj12, I knew my approach should work. The problem I was having was due to the host name I was given to connect to the database. It works fine if you enter it into SQL Developer as is. However, when I used it in the port forwarding, I could not connect to the database using SQL Developer using the host name localhost. The host name I was given had "scan" in the name. I think this is a Virtual IP. We use Oracle RAC which is a clustering technology. So I suspected to that the VIP selected a node on the cluster and the forwarder could not handle it. So this is how I solved the problem:
Installed Wireshark.
Start recording packets.
Used SQL Developer To Connect with the VIP - Success
In Wireshark, find the TCP Stream that contains something unique about the connection. In this case, the Oracle service name. You should see the IP of the VIP. Something like:
.........6.,.A ...O........:..............................(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=11.3.68.171)(PORT=1521))(CONNECT_DATA=(CID=(PROGRAM=SQL Developer)(HOST=jdbc)(USER=adpc))(SERVICE_NAME=svc1)(CID=(PROGRAM=SQL Developer)(HOST=jdbc)(USER=adpc)))).................6.,.A ...O........:..............................(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=11.3.68.171)(PORT=1521))(CONNECT_DATA=(CID=(PROGRAM=SQL Developer)(HOST=jdbc)(USER=adpc))(SERVICE_NAME=svc1)(CID=(PROGRAM=SQL Developer)(HOST=jdbc)(USER=adpc)))). .......6.A ........ ..........................
Now, go back to the packet and find out what the "real" address is. Here is an example:
Wire shark packet information. This is the destination IP where Oracle listener is.
Now use this to forward the port.
netsh interface portproxy add v4tov4 listenport=1521 connect address=11.3.68.135 connectport=1521 protocol=tcp
Now, when you log in using SQL Developer Basic Connection Type, you can use localhost instead of the VIP and you should be able to connect.
Now, go to another machine that has access to the machine you just set up and you should be able to connect to the database from there as well using the IP of the machine where you have port forwarding setup.
The same forward connection is working fine in both basic and advanced connection in SQL developer in my machine.
The only difference is machine A,B and Database are in the same network in my case where B can directly connect to the database also
Steps
1)You have to set up forwarding in machine A with machine A ip address as the listen address
2) Use the machine A ipaddress in TNS to connect to Database in machine B
If still, you are facing problems then you can try enabling log and trace files to identify the issue as mentioned in these articles
Oracle Database 10g Debugging Connection problems 1
Oracle Database 10g Debugging Connection problems 2
My idea is like this: The provider does not allow external mysql requests. I have been searching for hours for a solution to connect local java with remote server java. The remote java server would then make the mysql request and send it back.
Any ideas/Links for me?
You could do this with port forwarding, you can use ssh to setup a tunnel. So there is no need to write a java server program.
The last link have an example of your exact problem, though it is connecting to a PostgreSQL database, I translated that info to MySQL below.
An example here is when you need to connect to a database console, which only allows local connection for security reasons. Let’s say you’re running MySQL on your server, which by default listens on the port 3306.
$ ssh -L 9000:localhost:3306 user#example.com
The part that changed here is the localhost:3306, which says to forward connections from your local port 9000 to localhost:3306 on your server. Now we can simply connect to our database.
$ mysql -h localhost -p 9000
You should now be able connect your local java jdbc program with the url jdbc:mysql://localhost:9000/dbname and it will be tunneled to the remote database which would see your tunneled connection as a local connection.
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:9000/dbname","username", "password");
My java application is not connect with a specific database in MySQL on local host.'Connection refused' named error coming when I am trying to connect.
I have checked also service of MySQL its working because there is two db on local host, I am able to connect with one Db. I have googled all the things but my problem still not resolved.
Please check the Bind address
(https://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_bind-address) to see if you have altered the my.cnf|ini configuration file on mysql correctly.
Also if you are trying to connect using different machine then you have to create a user and grant him privileges like this to make the database available remotely
CREATE USER 'jeffrey'#'%' IDENTIFIED BY 'mypass';
GRANT ALL ON db1.* TO 'jeffrey'#'%';
Wildcard % is used to give access to any IP connecting your machine.
I have made a Netbeans application that is reliant on the DB Network Server in order to retrieve data. In Netbeans the code works fine and runs well. Outside of Netbeans everything but the database information is working. I have made a batch file for connecting to the localhost server that seems to connect on the port I assigned: 1527. Even after connecting to the localhost, it won't display the database information.
My code in the batch file:
PATH C:\Program Files\Java\jdk1.8.0_25\db\bin;%PATH%
startNetworkServer
When I run this I get the result:
Security manager installed using the Basic server security policy.
Apache Derby Network Server - 10.10.1.8 - (1557168) started and ready to accept connections on port 1527connect
Is there more code that I need to add in order to connect to the actual database itself from the server? Or is this not the right way to do this at all? I have tried using the Embedded DB but that didn't work and only caused more problems. I would prefer greatly to stay away from it and stick to the Network DB.
I am very New with Hbase, its really different from RDBMS. I developed a simple application and trying to configure it to remote server 162.18.17.55. I am getting connection refusing error. I am unable to to forward to check where it went wrong, when i type zk_dump in Putty , then i got the respective server details, I can login into putty and tables into database, but when i use java client i am not able to connect to server. please can any one guide me this process and issue
When you are connecting to Zookeeper it returns HadoopMaster as host instead of the ip address since you put HadoopMaster in your core-site.xml file. Now you need to add HadoopMaster in your /etc/hosts file to be able to recognize the host address. Add this line to your host file
162.18.17.55 HadoopMaster