I am currently trying to get a Java Applet to connect to a MySQL server. I have tested the MySQL server and verified that it works (I can connect with php). However, I can't seem to get my applet to connect.
我目前正在尝试将Java Applet连接到MySQL服务器。我测试了MySQL服务器并验证它是否有效(我可以用php连接)。但是,我似乎无法让我的applet连接。
Right now, I'm testing with Eclipse, and I have the following code listed below (which is NOT my own... just trying to get a connection at the moment).
现在,我正在使用Eclipse进行测试,并且我在下面列出了以下代码(这不是我自己的......目前只是尝试建立连接)。
However, it gives me a Communications Link Failure, and can't connect. Can someone please walk me through how to establish a connection on EC2? I'm new with both EC2 and Java-MySQL connections, and I'm not sure if the problem is with my code, my port configurations, or my Eclipse. Any help would be greatly appreciated!
但是,它给我一个通信链路故障,并且无法连接。有人可以告诉我如何在EC2上建立连接吗?我是新的EC2和Java-MySQL连接,我不确定问题是我的代码,我的端口配置还是我的Eclipse。任何帮助将不胜感激!
import java.sql.*;
import javax.swing.*;
import java.util.Properties;
public class HelloWorld extends JApplet
{
// The JDBC Connector Class.
private static final String dbClassName = "com.mysql.jdbc.Driver";
private static final String CONNECTION =
"jdbc:mysql://<IP of EC2>";
public static void main(String[] args) throws
ClassNotFoundException,SQLException
{
System.out.println(dbClassName);
// Class.forName(xxx) loads the jdbc classes and
// creates a drivermanager class factory
Class.forName(dbClassName);
// Properties for user and password.
Properties p = new Properties();
p.put("user","<username>");
p.put("password","<password>");
// Now try to connect
Connection c = DriverManager.getConnection(CONNECTION,p);
System.out.println("It works !");
c.close();
}
}
1 个解决方案
#1
0
(It's been two years. This needs to be removed from Unanswered -- see Comments for the Resolution.)
(已经过去两年了。这需要从未答复中删除 - 请参阅解决方案的评论。)
#1
0
(It's been two years. This needs to be removed from Unanswered -- see Comments for the Resolution.)
(已经过去两年了。这需要从未答复中删除 - 请参阅解决方案的评论。)