我无法通过 netbeans 连接到托管在 linux 服务器上的 MySQL 服务器。
当通过 MySQL Workbench “Standard TCP/IP through ssh”连接时,所有这些凭据都有效。
这是我的代码:
public class Database {
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://john.myschool.edu:3306/cs3610";
private static final String USERNAME = "mbrooke";
private static final String PASSWORD = "mypass";
private Connection connection;
public Database() throws Exception{
try{
connect();
}catch(SQLException e){
if(connection !=null){
connection.close();
}
}
}
//Open connection to database
private void connect() throws Exception{
connection = null;
Class.forName (DRIVER).newInstance ();
connection = DriverManager.getConnection(URL,USERNAME,PASSWORD);
}
}
我在以“connection = DriverManager ...”开头的行上收到带有#521 的 SQLException,但我不确定是什么导致了这个问题。驱动程序似乎已正确安装,因为在单步执行时,我通过了“Class.forName(D...”) 行,没有抛出异常。