Hi there!
I'm not sure what's wrong but it seems that everytime I try to connect JDBC with MySQL, it couldn't connect.
I made a very simple script which goes something like this:
It always says "Cannot Connect To Database Server".
Could anyone tell me what's wrong or what I did which is causing this error? Is the path to the database correct?
Please do help if you know how to solve this, I'm seriously confused.
Thanks for taking the time to look.
Ps. Error I'm getting is "java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)"
I'm not sure what's wrong but it seems that everytime I try to connect JDBC with MySQL, it couldn't connect.
I made a very simple script which goes something like this:
Code:
import java.sql.*;
public class Connect
{
public static void main (String[] args)
{
Connection conn = null;
String userName = "investmil_stock";
String password = "xxxxxx";
String url = "jdbc:mysql://127.0.0.1/investmil_stock";
try
{
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server");
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
It always says "Cannot Connect To Database Server".
Could anyone tell me what's wrong or what I did which is causing this error? Is the path to the database correct?
Please do help if you know how to solve this, I'm seriously confused.
Thanks for taking the time to look.
Ps. Error I'm getting is "java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)"
Last edited: