Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.
Hi!
I'm learning java and facing this weird situation. I've written a JApplet form which accepts data and passes them as a parameter to another class' constuctor. This another class uses JDBC to connect to PostgreSQL and adds the data to a table. I've tested this class by calling the same constructor from a method in a yet different class which is console based and found it to work well.
Back to the JApplet class file. When I run the form from the netbeans right click menu, I'm able to fill up the form and the data is added to the table. But when I call the applet from a HTML file, the form displays correctly but on pressing the submit button I get ClassNotFoundException. (This is because I don't handle this exception in the class file using JDBC but throw it in the constructor and ultimately catch it in the JApplet class.) What can possibly be going wrong here?
I'll post the code if anyone's interested.
Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.
I'd guess you are encountering a security issue...work around being to sign the applet...see the following link: What Applets Can and Cannot Do (The Java™ Tutorials > Deployment > Java Applets)
Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.
It might help if you posted the full text of the error message shown in the browser's java console.
It would say if there was a Permissions/security issue.
Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.
Thanks Norm and copeg for your opinions. I too suspect a permissions issue.
I enabled "show java console" in the sun java 6 plugin control panel and opened the web console in firefox browser, checked everything in it and tried running the applet again. Nothing came up in the console. Maybe I did it wrong.
Anyway, I've given up using the applet to add data to database. It occurred to me that since applet runs on client side while the database is supposed to be on the server side, this approach is flawed.
I'm gonna try using a servlet to do the JDBC work while the applet (invoked from a JSP) will just collect the data and pass it to the servlet. Is this approach better?
Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.
Quote:
Nothing came up in the console.
I don't understand how that can be. There is always something in the console.
Here is what is always at the beginning:
Java Plug-in 1.6.0_20
Using JRE version 1.6.0_25-b06 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Owner
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.
Maybe I was looking at the wrong console. Is the console something that has to be installed as an add-on separately?
Your post does remind me of something though. I think in windows you get an icon in system tray whenever there's some use of java plugin. Right clicking on it gives an option to see the console. I think I've seen something like what you've posted there. But I'm running linux now. Can't check if I'm right.
Did you find what you've posted in the console in firefox?
Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.
Yes, I think it was Firefox. I get the same console with Chrome.
2 Attachment(s)
Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.
Can you tell from the screenshot if I've opened the right console?
Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.
I've never seen that before.
Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.
Forget it then. Thanks a lot anyway for your time.
Cheers!!
Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.
Quote:
Anyway, I've given up using the applet to add data to database. It occurred to me that since applet runs on client side while the database is supposed to be on the server side, this approach is flawed.
I'm gonna try using a servlet to do the JDBC work while the applet (invoked from a JSP) will just collect the data and pass it to the servlet. Is this approach better?
Wouldn't say that approach is flawed per se - you still have to transfer the data so it probably wouldn't be faster. That being said placing the code on the server might make your application more maintainable. Should you make a servlet you should take care to code carefully to avoid things such as SQL injection. Further, you may still have security issues with an applet depending upon the server configuration.