简体   繁体   English

Java Applet在IDE中连接到mysql,但在Web浏览器中无法连接

[英]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. 我正在努力构建一个小程序,该小程序从MYSQL数据库获取输入文本并显示在屏幕上。 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 我在运行Netbeans时获得与MySQL的连接,但是在浏览器中运行相同的错误时却失败了

Communications link failure Last packet sent to the server was 0 ms ago. 通信链接故障发送到服务器的最后一个数据包是在0毫秒前。

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. 我也尝试过* 签署* JAR。 But still it's not working. 但仍然无法正常工作。

Below is the code of the class which I want to execute from My JAR archive. 下面是我想从My JAR存档中执行的类的代码。

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?? 如果不可能的话,还有没有其他方法可以从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. 从Netbeans运行时,小程序从应用程序文件夹的/test目录或/build目录运行。 Usually the drivers will be in /lib so no problem here. 通常,驱动程序位于/lib因此在这里没有问题。

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. 从浏览器运行时,该applet将通过其自己的jar文件运行,因此您需要确保所需的所有库(JDBC驱动程序)都位于类路径上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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