connection has a remote Database - java

I use H2 Database as DBMS from a remote computer,so I enabled remote access from a browser as follows:
webAllowOthers=true
but when i try to connect to the server from my java application i get this error from H2:
remote connections to this server are not allowed
screenshot:
And also already looking into the code Analyzer with (Error Code: 90117):
REMOTE_CONNECTION_NOT_ALLOWED = 90117
The error with code 90117 is thrown when trying to connect to a TCP server from another machine, if remote connections are not allowed. To allow remote connections, start the TCP server using the option -tcpAllowOthers as in:
java org.h2.tools.Server -tcp -tcpAllowOthers
Or, when starting the server from an application, use:
Server server = Server.createTcpServer("-tcpAllowOthers");
server.start();
I do not understand how to activate the tcpAllowOthers, it does not exist in .h2.server.properties ?

There are two different server:
the Web Console server that is used to run the H2 Console tool (the GUI tool). It can be accessed by a browser only.
the TCP server that allows to connect an application that uses JDBC, when using the client/server mode (jdbc:h2:tcp://localhost/~/test)
The file .h2.server.properties is only used for the Web Console server. It only supports webAllowOthers=true. This file is not used by the TCP server.
To enable remote access to the TCP server, you need to start the TCP server using the option -tcpAllowOthers. To start both the Web Console server (the H2 Console tool) and the TCP server with remote connections enabled, you would need to use:
java -jar h2*.jar -web -webAllowOthers -tcp -tcpAllowOthers -browser
(this also starts a browser)

Related

How to connect remotely via tcp to the h2 database?

I am trying to start H2 in server mode to connect an application from another computer. But no matter how hard I have tried, I have not succeeded.
I have seen the documentation and to start the server from the command line is executed:
java -cp h2-2.1.214.jar org.h2.tools.Server -tcpAllowOthers
output:
TCP server running at tcp://127.0.1.1:9092 (others can connect)
PG server running at pg://127.0.1.1:5435 (only local connections)
Web Console server running at https://127.0.1.1:8082 (others can connect)
now from the other pc, as I understand I must execute the connection in the following way:
jdbc:h2:tcp://[server][:port]/[path]/[databaseName]
then it should be:
jdbc:h2:tcp://127.0.1.1:9092/home/mateo/database
But I have read that 127.0.1.1 only works locally. I have also noticed that when I open H2 Console in the examples I have seen, the machine's ip appears, that is to say: 192.168.X.
What am I doing wrong?
(Update)
I am currently using Linux.
I have launched the server from Windows and managed to connect it from Linux successfully following the above steps. But, I still don't understand why it doesn't work in Linux, in Windows it loads the server with the IP address of the machine. It makes me think that I have to do some additional configuration for Linux.
server running
You need to replace local IP address in your JDBC URL with real non-local IP address of your server (jdbc:h2:tcp://127.0.1.1:9092/*** -> jdbc:h2:tcp://192.168.1.4:9092/***, for example). H2 listens all network interfaces of the host, it doesn't matter which address was reported in “runnig at …” message.
You also may need to protect ports 8082 and 9092 from connections from untrusted systems if you have them in your internal network and from connections from external network (make sure your router or whatever you have doesn't redirect connections to the host with database server).

How connect local java program with remote server java for mysql request?

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");

jprofiler jpcontroller can't connect to jvm when called with host:port

i want to profile my web application now this is what i do:
run jpenable.exe and after it finds thi jvm, it gives me a port so i can connect to it using JProfiler GUI(for instance:12121)! now as I want to have commandline control i then try to connect jpcontroller using this command:
jpcontroller.exe localhost:12121
but it cannot connect and sticks there with no error! now if i use this command:
jpcontroller.exe <port>
then it works!
but actually i can't do this as i want to connect to a remote jvm!!
am i wrong some where?
jpcontroller does not connect to the port that is opened by the profiling agent, but it uses JMX to connect to the process. For that to work on a remote computer, add the VM parameter
-Djprofiler.jmxServerPort=[port]
to the profiled process and use that port in jpcontroller. Then, an MBean server will be created that listens on that port.

Java server on OpenShift

At the moment i have an android client app which connects to my java server through socket - serversocket. It sends and receive strings. The java server is connected to a mysql database (actually mariadb) using the jdbc driver.
I succeed to create a jbossas application and upload the code of the java server to openshift, but i didn't find any detailed tutorial on how do i connect to this new uploaded server from my socket client (This one (RMI or socket connection to Java Program on OpenShift) gives some tips but i'm still stucked).
More on this, how do i know that my server runs just fine on openshift and how do i control de calls to the database after i connect it (found this: $ rhc app create MyApp jbossas-7
$ rhc cartridge add mysql-5.5 -a MyApp), using org.mariadb.jdbc.Driver and java.sql is still working ?
Any small guide or tip is highly appreciated. I'm new to these things so please don't be too heavy on comments.
You can only make connections to your OpenShift server on http/https or ws/wss ports. If you want to connect to your java application and pull data from it from an android device, I would suggest using a RESTful api or a servlet, etc.
I had similar problem: My app server originally was running as a ServerSocket listener, and any clients/devices connect to it directly via Socket binding.
To deploy it into OpenShift, my previous initial solution was to change its host:port configuration by following the suggestion as described in this link [Socket connection to Java Program on OpenShift]. It worked nice as far as my app server was successfully up and running. But it did not work well with the port forwarding approach in order to accept remote requests.
So for the final solution, I modified the app server by wrapping my original code with a RESTful webservice around it, and deploy it as a web service.

connect remote MQ using Java?

Friends,
I installed IBM explorer 7.1 which have server and GUI. Locally I connected the queue using inter process communication. Now I need to connect the server QM from remote machine using java standalone program.
In server I have created a queue, port and server channel. when I trying to connect using host name , unable to get the connection. Is this the right way?. else I have to install client where I tried connect that server.but getting error code 2035 when i run that java program. listener and queue manage is running in remote machine. Some forum i seen that AMQCLCHL.TAB file using for client connection. I had confusion whether i have to use that for client connection. if yes how i can use that?

Categories