Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    26
    My Mood
    Fine
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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)

  3. The Following User Says Thank You to copeg For This Useful Post:

    Lord Voldemort (July 12th, 2011)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.

  5. The Following User Says Thank You to Norm For This Useful Post:

    Lord Voldemort (July 12th, 2011)

  6. #4
    Junior Member
    Join Date
    Jun 2011
    Posts
    26
    My Mood
    Fine
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default 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?

  7. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.

    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>
    ----------------------------------------------------

  8. #6
    Junior Member
    Join Date
    Jun 2011
    Posts
    26
    My Mood
    Fine
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default 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?
    Last edited by Lord Voldemort; July 12th, 2011 at 12:38 PM. Reason: second thoughts

  9. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.

  10. #8
    Junior Member
    Join Date
    Jun 2011
    Posts
    26
    My Mood
    Fine
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default 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?
    Attached Images Attached Images
    Last edited by Lord Voldemort; July 12th, 2011 at 12:58 PM.

  11. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.

    I've never seen that before.

  12. #10
    Junior Member
    Join Date
    Jun 2011
    Posts
    26
    My Mood
    Fine
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default 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!!

  13. #11
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Form using JDBC works in Netbeans but ClassNotFoundEx when called from HTML doc.

    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.

Similar Threads

  1. GUI Only Works Sometimes
    By bgd223 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: July 12th, 2011, 08:08 AM
  2. Any way to write html form data to file?
    By nathan.fortier@gmail.com in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: January 14th, 2011, 03:03 PM
  3. Replies: 0
    Last Post: February 22nd, 2010, 01:21 AM
  4. Replies: 0
    Last Post: February 2nd, 2010, 08:20 AM
  5. Java Swing :Back Button from one form to another form
    By srinivasan_253642 in forum AWT / Java Swing
    Replies: 1
    Last Post: December 26th, 2009, 09:51 AM

Tags for this Thread