简体   繁体   中英

Java applet connects to mysql in IDE but fails to connect in web browser

I am trying hard to build an applet which takes input text from MYSQL database and displays on the screen. I get the connection to MySQL in when I run it netbeans but it fails when I run the same in browser with the error

Communications link failure Last packet sent to the server was 0 ms ago.

Believe me I went through all the posts related to mine on this forum. But none of them was useful to me. I also tried * signing * the JAR. But still it's not working.

Below is the code of the class which I want to execute from My JAR archive.

String url = "jdbc:mysql://127.0.0.1/MYdb";
Connection con = DriverManager.getConnection(url,"root", "pass");

I went through all possible solutions on net. And finally I am posting over here. Please help me in this. If it's not possible the is there any other way to fetch data from database in an applet?? I am waiting for your valuable reply. Thank you.

When run from Netbeans, the applet runs from the /test directory or /build directory, from the application folder. Usually the drivers will be in /lib so no problem here.

When run from browser, the applet will be running from it's own jar file, so you will need to make that all the libraries (JDBC drivers) required are on your classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM