Results 1 to 15 of 15
  1. #1
    axxofreak is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default SQL in an applet on a server....

    I made a march madness bracket applet for a fundraiser (March Madness Bracket) and it all works fine except it wont connect to submit to an SQL Server.

    When I was developing it, I could connect remotely with my server's IP just fine, but when I put all the applet and html files on the server for the site and change it to localhost, it will not connect anymore.

    I could connect fine remotely with my IP whitelisted but when it is on the server trying to access the database at localhost, it wont connect.

    my connect statement is:
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/dataebase_name","user","pass");

    obviously i removed my user info from it and before it worked with the IP address with port 3306, and localhost with port 3306 doesnt work, I tried.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    Sign the applet. I'm guessing a security exception is being thrown when you attempt to access the database.

  3. #3
    axxofreak is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    I get a connection exception, but I will try signing it. Anyway you could point me to a good tutorial?

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    Post the full exception - it gives a world of context to the problem.

    Here's one tutorial
    OTN Discussion Forums : How to sign an applet (and get it to ...

  5. #5
    axxofreak is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    here is what I get:

    Got an exception!
    Communications link failure

    The last packet successfully received from the server was 16 milliseconds ago. The last packet sent successfully to the server was 16 milliseconds ago.

    that is with the IP address for the server and the school's IP whitelisted, with localhost it is:

    Got an exception!
    Communications link failure

    The last packet successfully received from the server was 0 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    You're not printing stack traces then in your exception handling.

    However, signing the applet is going to be one step you need to do since the security model for applets means they cannot connect to any server other than the one they were downloaded from.

  7. #7
    axxofreak is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    The database is on the same server that it is being downloaded from, what do you mean by printing stack traces?

    would it help if I uploaded my code? Also this signing process is very confusing to me, if anyone could sheed some more light on that, that would be awesome!


    to print my exception i do e.getMessage();
    my exception is a communications link failure.
    Last edited by axxofreak; 03-17-2011 at 03:29 PM.

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    OK.
    If it's the same server then it's likely something else is up.

    getMessage() loses so much information, and is usually next to useless.
    You want printStackTrace().

  9. #9
    axxofreak is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    I actaully did that right as you posted. Here is the stack

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:40 7)
    at com.mysql.jdbc.SQLError.createCommunicationsExcept ion(SQLError.java:1116)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:346)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(Connecti onImpl.java:2334)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(Co nnectionImpl.java:2371)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(Connecti onImpl.java:2163)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImp l.java:794)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connect ion.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:40 7)
    at com.mysql.jdbc.ConnectionImpl.getInstance(Connecti onImpl.java:378)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:305)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at Main.sendSQL(Main.java:420)
    at Main.actionPerformed(Main.java:263)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)
    at com.mysql.jdbc.StandardSocketFactory.unwrapExcepti onToProperClassAndThrowIt(StandardSocketFactory.ja va:405)
    at com.mysql.jdbc.StandardSocketFactory.connect(Stand ardSocketFactory.java:266)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:295)
    ... 40 more



    I say the socket error, so I assume that I need to sign it for it to work. And I am very confused about that!

  10. #10
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    There you go:
    Caused by: java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)

    As you say, that's the Applet security at work.

    Can't help with signing I'm afraid. Never had to do it.

  11. #11
    axxofreak is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    I think I got my head kind of around the whole signing situation, I am making this other kid who helped me make the applet figure out how to sign it I think :P

    I did the programming so that job is on him now!
    but if anyone has a good guide on signing applets, PLEASE LET ME KNOW!

  12. #12
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    Quote Originally Posted by axxofreak View Post
    I think I got my head kind of around the whole signing situation, I am making this other kid who helped me make the applet figure out how to sign it I think :P

    I did the programming so that job is on him now!
    but if anyone has a good guide on signing applets, PLEASE LET ME KNOW!
    See the link I posted above. Worked for me first time through. If this is something you must do often, I'd recommend writing an ant build file that incorporates a signing step

  13. #13
    axxofreak is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    Nah I dont have to often.

    Do you need to purchase a certificate? From what I understand you can purchase an official one (for like 300 bucks) or just make your own less official one, with the JDK.

    And will that tutorial work for JDK 1.6?

  14. #14
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    Should work for 6.0, but I honestly haven't tried the full procedure with 6.0. You can make your own certificate, just doesn't look as official sounding as something like a verisign signature.

  15. #15
    axxofreak is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    We got the jar signed, but now we get this "sandbox" exception. I read that I need to include the java.policy file in with the jar, is that right? What do you think?

    Got an exception!
    trusted loader attempted to load sandboxed resource from March Madness Bracket
    java.lang.SecurityException: trusted loader attempted to load sandboxed resource from March Madness Bracket
    at com.sun.deploy.security.CPCallbackHandler$ParentCa llback.check(Unknown Source)
    at com.sun.deploy.security.CPCallbackHandler$ParentCa llback.access$1500(Unknown Source)
    at com.sun.deploy.security.CPCallbackHandler$ChildEle ment.checkResource(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.checkResourc e(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at Main.sendSQL(Main.java:414)
    at Main.actionPerformed(Main.java:263)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

Similar Threads

  1. Communicating From client applet to my server
    By aaroncarpet in forum Java Applets
    Replies: 3
    Last Post: 12-17-2010, 11:53 PM
  2. Client-Server in applet
    By bobo67 in forum Java Applets
    Replies: 17
    Last Post: 10-10-2010, 07:40 PM
  3. Applet Server Write Permission
    By Look2Logic in forum New To Java
    Replies: 0
    Last Post: 04-13-2010, 09:21 PM
  4. Getting the locale of the server who initiated the applet
    By prachi_goliwadekar in forum Java Applets
    Replies: 3
    Last Post: 03-29-2009, 08:45 PM
  5. Applet connecting to server
    By zenMarko in forum Java Applets
    Replies: 1
    Last Post: 11-15-2008, 04:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •