JApplet connects to localhost Mysql through Eclipse, but not web browser - java

So I wrote a JApplet that connects to and does some stuff with a MySQL server.
When I test it in Eclipse it works just fine. I have the IP address, the database name, the username I'm using (root) and the password hardcoded into the program at the moment.
If I have the IP as localhost, or 127.0.0.1 (same thing but yeah), or 192.168.x.x (my PC's local address) the JApplet while being run from Eclipse will connect to the MySQL server with no issues. Also, if I open another terminal and login to mysql that way it also works.
However, if I jar the project using Eclipse, include the mysql driver in the HTML applet tag and run it through a web browser on the same machine it does not work.
Here is the HTML tag that I am using:
<applet code="mysqlApp.MysqlInterface.class"
archive="LoginDemo.jar, mysql-connector-java-5.1.18-bin.jar"
height="150" width="450">
Your browser does not support the <code>applet</code> tag.
</applet>
I have tried it in Firefox 10.* with port 3306 forwarded on my router and my software firewall turned off. Also, the MySQL server is bound to 0.0.0.0 (it accepts connection attempts on all interfaces) and TCP/IP is enabled (skip-networking option is not used). I get a message dialog window saying that no sql connection can be made (what I programmed it to do) and I get the following exception in the Java console:
SQLException: 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.
SQLState: 08S01
VendorError: 0
I also tried it in the latest version of Internet Explorer for Windows 7 x64 and when I click on the buttons that are supposed to connect it to the server the webpage freezes.
Nothing prints out to the console where mysqld is running (I ran it with an admin terminal using mysqld --console)
Does anybody have any ideas? I have been looking for a solution for days but everything I find that seems like it may work has one or two little details that makes it not applicable to my issue.
Yes, I know that I should not be having the applet communicate directly with the database if this is to be used in production code (major security issue) but I am in the early stages of doing this and am trying to figure this out for testing purposes.
Thanks.

You should have your applet communicate to some backend (java or php) through ajax. Then use the backend to communicate with mysql. A good place for ajax is http://prototypejs.org/assets/2010/10/12/prototype.js.

Related

Running java on remote desktop connection

I'm trying to run selenium/java scripts on remote server using windows remote desktop connection. I'm pretty new to these things.
I got two ideas in my mind one is to use selenium grid and another one is to use sockets for connecting.
I'm running this script for 404 validation over 1000 urls. I have the code that'll run fine in my local machine but due to frequent network issues my organization wants to run on remote server.
I got access for that server on port 3389 and credentials for remote desktop connection.
Now how to do this?

java.sql.sqlnontransientconnectionexception: java.net.connectException : error connecting to server localhost on port

I've being working on a java project using Derbyclient (database locally hosted). I'm done with everything except that when I'm trying the desktop app while I'm not manually connected to the database (from Netbeans), the error in the title pops up and I can't seem to solve it. Thank you for taking the time to read this and help me.
Derby can be run in two modes embedded or server-based. Server-based allows multiple programs to access the same database. Embedded allows your application to run without a server. Your url selects server-based. The connection refused error indicates that the server is not running. Since the server was started within Netbeans it is shutdown when Netbeans is not running.
The options are:
Switch to embedded.
Start the server with a command outside Netbeans.
Just keep Netbeans running.
To switch to embedded see Apache's documentation for deployment options:
Eliminate the "//localhost:1527" from the url.
also see the tutorial "Run SQL using the embedded driver" at https://builds.apache.org/job/Derby-docs/lastSuccessfulBuild/artifact/trunk/out/getstart/index.html
To start the server in a seperate command window see the syntax for derbyrun.jar:
https://builds.apache.org/job/Derby-docs/lastSuccessfulBuild/artifact/trunk/out/getstart/rgsderbyrunjarsyntax.html

How to create a batch file for connecting to Java DB Network Server

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.

App Java and hosting mysql

I have a Java application and I have to connect to a MySQL DB host in aruba.it. If I make a connection, aruba.it refuses that. How to solve this?
To start, I assume that you're trying to run this Java application locally, or at least at a different machine than where the MySQL DB runs and that you got a SQLException: Connection Refused.
To fix the particular problem, all routers and firewalls in the complete network pipe between the client (where the Java application runs) and the server (where the MySQL DB runs) needs to be configured to allow/forward the port number which the DB uses. This is by default 3306. If this port is blocked, you cannot reach the DB from outside.
Another solution is just to upload the Java application in flavor of a webapplication and run it by HTTP. You'd normally use JSP/Servlet for this.
Apart from network, routers, firewall issues the reason can be that by default remote access to MySQL database server is disabled for security reasons. Mostly DB is hosted on the same server or on the trusted server. If you run java application from your desktop, you need to configure MySQL so it will accept this connections. See this manual for details how to do it.

Why http://localhost:8080 available while 127.0.0.1 not? (JSP on MyEclipse+Tomcat)

The System's hosts file is fine, 127.0.0.1 localhost is there...
Ping 127.0.0.1,or my IP, the result is also fine..
Myeclipse's version is 8.0 and I'm just using the Tomcat within it.
A simple JSP+Javabean web project so is deployed.
Now the situation is when I open MyEclipse and start the Tomcat, I can access my site throuth
http://localhost:8080/so/index.jsp, and it displays and runs well (this means 8080 port is all right,right?).But http://127.0.0.1:8080/so/index.jsp is a blank page(no source code) in K-Meleon and the page can't be found in IE.
Still when I tried to access it from another pc in LAN, 'http://myIP:8080/so/index.jsp', it worked only a little. The browser can load the homepage but without CSS, and clicking on any link or even refreshing the page leads to an error page..(While the site gose quite well on my own pc accessed throught localhost)
Is there anyone have ever met this situation?
If you configured tomcat to only listen on the non-loopback interface, this is what you'd get.
See this description of how this gets configured in server.xml.
Use the netstat -a to see what your tomcat is actually listening on.

Categories