Results 1 to 15 of 15
Thread: SQL in an applet on a server....
- 03-16-2011, 07:24 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
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.
- 03-16-2011, 08:39 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
Sign the applet. I'm guessing a security exception is being thrown when you attempt to access the database.
- 03-16-2011, 10:10 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
I get a connection exception, but I will try signing it. Anyway you could point me to a good tutorial?
- 03-16-2011, 10:33 PM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
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 ...
- 03-17-2011, 12:14 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
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.
- 03-17-2011, 01:16 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 03-17-2011, 03:26 PM #7
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
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.
- 03-17-2011, 03:37 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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().
- 03-17-2011, 03:48 PM #9
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
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!
- 03-17-2011, 04:11 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 03-17-2011, 05:26 PM #11
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
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!
- 03-17-2011, 05:33 PM #12
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
- 03-17-2011, 06:38 PM #13
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
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?
- 03-17-2011, 07:36 PM #14
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
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.
- 03-18-2011, 03:49 PM #15
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
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
-
Communicating From client applet to my server
By aaroncarpet in forum Java AppletsReplies: 3Last Post: 12-17-2010, 11:53 PM -
Client-Server in applet
By bobo67 in forum Java AppletsReplies: 17Last Post: 10-10-2010, 07:40 PM -
Applet Server Write Permission
By Look2Logic in forum New To JavaReplies: 0Last Post: 04-13-2010, 09:21 PM -
Getting the locale of the server who initiated the applet
By prachi_goliwadekar in forum Java AppletsReplies: 3Last Post: 03-29-2009, 08:45 PM -
Applet connecting to server
By zenMarko in forum Java AppletsReplies: 1Last Post: 11-15-2008, 04:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks