Advertisement
Guest User

Untitled

a guest
Jul 31st, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
  2.  
  3. ** BEGIN NESTED EXCEPTION **
  4.  
  5. java.net.SocketException
  6. MESSAGE: java.security.AccessControlException: access denied ("java.net.SocketPermission" "[0:0:0:0:0:0:0:1]:3306" "connect,resolve")
  7.  
  8. STACKTRACE:
  9.  
  10. java.net.SocketException: java.security.AccessControlException: access denied ("java.net.SocketPermission" "[0:0:0:0:0:0:0:1]:3306" "connect,resolve")
  11. at com.mysql.jdbc.StandardSocketFactory.unwrapExceptionToProperClassAndThrowIt(StandardSocketFactory.java:407)
  12. at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:268)
  13. at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
  14. at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
  15. at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
  16. at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
  17. at java.sql.DriverManager.getConnection(DriverManager.java:664)
  18. at java.sql.DriverManager.getConnection(DriverManager.java:247)
  19. at com.ia.client.IAConnection$1.run(IAConnection.java:27)
  20. at com.ia.client.IAConnection$1.run(IAConnection.java:24)
  21. at java.security.AccessController.doPrivileged(Native Method)
  22. at com.ia.client.IAConnection.<init>(IAConnection.java:24)
  23. at com.ia.client.IADriver.connect(IADriver.java:31)
  24. at com.ia.client.IADriver.connect(IADriver.java:14)
  25. at java.sql.DriverManager.getConnection(DriverManager.java:664)
  26. at java.sql.DriverManager.getConnection(DriverManager.java:247)
  27. at Main.main(Main.java:24)
  28. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  29. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  30. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  31. at java.lang.reflect.Method.invoke(Method.java:483)
  32. at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
  33.  
  34.  
  35. ** END NESTED EXCEPTION **
  36.  
  37.  
  38.  
  39. Last packet sent to the server was 0 ms ago.
  40. at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847)
  41. at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
  42.  
  43. public class IAConnection implements Connection {
  44.  
  45. private Connection connection;
  46. public static final String USER_PROPERTY_KEY = "user";
  47. public static final String PASSWORD_PROPERTY_KEY = "password";
  48.  
  49. public IAConnection(String url, Properties info ){
  50. //if()
  51. try {
  52. Class.forName("com.mysql.jdbc.Driver");
  53. connection = AccessController.doPrivileged(new PrivilegedExceptionAction<Connection>() {
  54. public Connection run() throws IOException {
  55. try {
  56. return DriverManager.getConnection("jdbc:mysql://localhost/database-erp",info.getProperty(USER_PROPERTY_KEY),info.getProperty(PASSWORD_PROPERTY_KEY));
  57. }catch (Exception e){
  58. e.printStackTrace();
  59. }
  60. return null;
  61. }
  62. });
  63. System.out.println("connection created: "+connection.toString());
  64. }catch (Exception e){
  65. e.printStackTrace();
  66. }
  67.  
  68. }
  69. //other methods
  70. }
  71.  
  72. public class IADriver implements java.sql.Driver {
  73.  
  74. static {
  75. try {
  76. // Register the IADriver with DriverManager
  77. IADriver driverInst = new IADriver();
  78. DriverManager.registerDriver(driverInst);
  79. System.setSecurityManager(new RMISecurityManager());
  80. } catch (Exception e) {
  81. System.out.print("Error occured:" + e);
  82. }
  83.  
  84. }
  85.  
  86. @Override
  87. public IAConnection connect(String url, Properties info) throws SQLException {
  88. if (url.contains("proxy")) {
  89. return new IAConnection(url, info);
  90. } else {
  91. return null;
  92. }
  93. }
  94.  
  95. @Override
  96. public boolean acceptsURL(String url) throws SQLException {
  97. return url.contains("proxy");
  98. }
  99.  
  100. @Override
  101. public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
  102. return new DriverPropertyInfo[0];
  103. }
  104.  
  105. @Override
  106. public int getMajorVersion() {
  107. return 0;
  108. }
  109.  
  110. @Override
  111. public int getMinorVersion() {
  112. return 0;
  113. }
  114.  
  115. @Override
  116. public boolean jdbcCompliant() {
  117. return false;
  118. }
  119.  
  120. @SuppressWarnings("Since15")
  121. @Override
  122. public Logger getParentLogger() throws SQLFeatureNotSupportedException {
  123. return null;
  124. }
  125. }
  126.  
  127. public class Main {
  128.  
  129. public static void main(String[] args) {
  130. try {
  131.  
  132. Class.forName("com.ia.client.IADriver");
  133. Connection connnection = DriverManager.getConnection("jdbc:proxy://localhost/database-erp","root","root");
  134. }catch (Exception e){
  135. e.printStackTrace();
  136. }
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement