This discussion is archived
1 2 Previous Next 23 Replies Latest reply: Oct 15, 2001 12:21 PM by 807587 RSS

Using Applets with JDBC

807587 Newbie
Currently Being Moderated
I am developing a Java app that requires access to a RDBMS. I'm having good success connecting to the DB as a Java app but when I try to run it as an applet, I'm getting the following SQLException error:

"No suitable driver"

I have created a policy file that grants me the required RuntimePermission and PropertyPermission. Any idea what else I'm missing?

Thanks,
PjR
  • 1. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    Presumably your applet tag references the jar containing the Driver implementation and you've successfully registered the driver?
  • 2. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    Some clarification ... I'm using the JDBC-ODBC driver and, yes the driver is reqistered properly (again, it's running fine as a Java application).

    I'm using the appletviewer to test the applet and that is where I'm getting the error. Are there any adidtional parameters that I should be adding to the <APPLET> tag?

    Thanks,
    PjR.
  • 3. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    Can you provide more information about where you're getting this exception and whether you're registering the driver using Class.forName()?
  • 4. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    I'm getting the error message when I'm trying to connect to the database ... it's throwing an SQLException error, not a ClassNotFoundException.

    I think that the error message is a bit misleading as it has no problem finding the driver. In any event, the driver is being registered using:

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver" )

    PjR.
  • 5. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    Presumably the stack trace indicates that the exception originates in DriverManager and not JdbcOdbcDriver?
  • 6. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    1. You will have the class available to you when you compile your code. So try using

    DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());

    and see what exception you get then.

    2. ODBC-DSN is a local property of your machiene which will NOT be available to your applet when it runs on your client machiene, so unless you have a very targeted client base and you are sure that you client will have the ODBC-DSN with the same name created on his system, you should not go throught the JDBC-ODBC bridge.

    3. Talking to the database directly from the Applet is not a good practice, you might run into some security issues when you deploy your applet in a production enviorment.

    Hope this helps
    Regards
    Omer
  • 7. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    Actually, the stack trace is not originating at the driver at all. It's referring to the implementation of the actionPerformed method of the ActionListener class.

    It definitely has to do with the fact that it's running as an applet instead of an application.

    Thanks,
    PjR
  • 8. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    I would definitely agree with Omer - Applets and ODBC (and arguably JDBC) seem like odd companions and should be avoided: if you can set up an ODBC data source then you can probably install a full-blown Java application as well.

    Your exception must be originating within JDBC somewhere - any chance of you posting the stack trace?
  • 9. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    Thanks for the reply. See responses below ...
    1. You will have the class available to you when you
    compile your code. So try using

    DriverManager.registerDriver(new
    sun.jdbc.odbc.JdbcOdbcDriver());

    and see what exception you get then.
    Same result as using Class.forName().
    2. ODBC-DSN is a local property of your machiene
    which will NOT be available to your applet when it
    runs on your client machiene, so unless you have a
    very targeted client base and you are sure that you
    client will have the ODBC-DSN with the same name
    created on his system, you should not go throught the
    JDBC-ODBC bridge.

    3. Talking to the database directly from the Applet
    is not a good practice, you might run into some
    security issues when you deploy your applet in a
    production enviorment.
    Points 2 & 3 well taken. Fortunately, we do have a very small user base and it's no problem having to register the DSN's on each machine.

    Our situation is that we're using a combination of platforms for this application. It's also limited to our Intranet so security isn't an issue.

    Thanks for the reply!
    Hope this helps
    Regards
    Omer
  • 10. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    Cannot get a connection to the database. <-- my code
    No suitable driver <-- SQLException.getMessage()
    Exception occurred during event dispatching: <-- stackTrace
    java.lang.NullPointerException
    at DbaApplet.actionPerformed(DbaApplet.java:76)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:14
    50)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
    ctButton.java:1504)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
    .java:378)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250
    )
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
    istener.java:216)
    at java.awt.Component.processMouseEvent(Component.java:3717)
    at java.awt.Component.processEvent(Component.java:3546)
    at java.awt.Container.processEvent(Container.java:1164)
    at java.awt.Component.dispatchEventImpl(Component.java:2595)
    at java.awt.Container.dispatchEventImpl(Container.java:1213)
    at java.awt.Component.dispatchEvent(Component.java:2499)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451
    )
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)

    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
    at java.awt.Container.dispatchEventImpl(Container.java:1200)
    at java.awt.Component.dispatchEvent(Component.java:2499)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
    at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:10
    3)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
  • 11. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    You're throwing the NullPointerException?

    Multiple platforms certainly doesn't imply Applets! ODBC would seem like an even less likely choice in that case.
  • 12. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    Just for the sake of interest (because it really doesn't focus on this problem) let me explain.

    We use Lotus Domino for many of our applications. Great platform RAD for apps that require document flow and messaging features. These documents display nicely in a Notes client. If our only requirement was to show information pertaining to a contract, for example, we wouldn't need Java.

    However, as you know, things are rarely that simple. The users would also like to see cash transactions for each contract when they are reviewing it. Domino does not lend itself to storing transactional information ...

    Soooo ... by multiple platform, I mean that some info is stored in Domino docs and other info is stored on SQL Server. It was thought that Java may be a nice way to integrating the two by displaying the transactions in a JTable when displaying the contract in a browser. That's what we're trying to prototype.

    Thanks for the input.

    PjR.
  • 13. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    Basically your trying to refrence methods or variables of a variable that is set to null in your class; should be on line 76 of your source code in the file DbaApplet.java in the method actioinPerformed.

    If you cant figure it out post the code and lets see what the problem is. :-)

    Regards
    Omer
  • 14. Re: Using Applets with JDBC
    807587 Newbie
    Currently Being Moderated
    The "null" variable is the variable used to store my Connection class. My code ordinarily would exit the applet if it couldn't establish a db connection, but just to show that the stack trace wasn't origination with the JDBC driver, I continued to let it run.

    I think that it has everything to do with the data source configuration. I will experiment with that.

    Thanks for the help!!

    PjR.
1 2 Previous Next