Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- ** BEGIN NESTED EXCEPTION **
- java.net.SocketException
- MESSAGE: java.security.AccessControlException: access denied ("java.net.SocketPermission" "[0:0:0:0:0:0:0:1]:3306" "connect,resolve")
- STACKTRACE:
- java.net.SocketException: java.security.AccessControlException: access denied ("java.net.SocketPermission" "[0:0:0:0:0:0:0:1]:3306" "connect,resolve")
- at com.mysql.jdbc.StandardSocketFactory.unwrapExceptionToProperClassAndThrowIt(StandardSocketFactory.java:407)
- at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:268)
- at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
- at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
- at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
- at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
- at java.sql.DriverManager.getConnection(DriverManager.java:664)
- at java.sql.DriverManager.getConnection(DriverManager.java:247)
- at com.ia.client.IAConnection$1.run(IAConnection.java:27)
- at com.ia.client.IAConnection$1.run(IAConnection.java:24)
- at java.security.AccessController.doPrivileged(Native Method)
- at com.ia.client.IAConnection.<init>(IAConnection.java:24)
- at com.ia.client.IADriver.connect(IADriver.java:31)
- at com.ia.client.IADriver.connect(IADriver.java:14)
- at java.sql.DriverManager.getConnection(DriverManager.java:664)
- at java.sql.DriverManager.getConnection(DriverManager.java:247)
- at Main.main(Main.java:24)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:483)
- at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
- ** END NESTED EXCEPTION **
- Last packet sent to the server was 0 ms ago.
- at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847)
- at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
- public class IAConnection implements Connection {
- private Connection connection;
- public static final String USER_PROPERTY_KEY = "user";
- public static final String PASSWORD_PROPERTY_KEY = "password";
- public IAConnection(String url, Properties info ){
- //if()
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connection = AccessController.doPrivileged(new PrivilegedExceptionAction<Connection>() {
- public Connection run() throws IOException {
- try {
- return DriverManager.getConnection("jdbc:mysql://localhost/database-erp",info.getProperty(USER_PROPERTY_KEY),info.getProperty(PASSWORD_PROPERTY_KEY));
- }catch (Exception e){
- e.printStackTrace();
- }
- return null;
- }
- });
- System.out.println("connection created: "+connection.toString());
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- //other methods
- }
- public class IADriver implements java.sql.Driver {
- static {
- try {
- // Register the IADriver with DriverManager
- IADriver driverInst = new IADriver();
- DriverManager.registerDriver(driverInst);
- System.setSecurityManager(new RMISecurityManager());
- } catch (Exception e) {
- System.out.print("Error occured:" + e);
- }
- }
- @Override
- public IAConnection connect(String url, Properties info) throws SQLException {
- if (url.contains("proxy")) {
- return new IAConnection(url, info);
- } else {
- return null;
- }
- }
- @Override
- public boolean acceptsURL(String url) throws SQLException {
- return url.contains("proxy");
- }
- @Override
- public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
- return new DriverPropertyInfo[0];
- }
- @Override
- public int getMajorVersion() {
- return 0;
- }
- @Override
- public int getMinorVersion() {
- return 0;
- }
- @Override
- public boolean jdbcCompliant() {
- return false;
- }
- @SuppressWarnings("Since15")
- @Override
- public Logger getParentLogger() throws SQLFeatureNotSupportedException {
- return null;
- }
- }
- public class Main {
- public static void main(String[] args) {
- try {
- Class.forName("com.ia.client.IADriver");
- Connection connnection = DriverManager.getConnection("jdbc:proxy://localhost/database-erp","root","root");
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement