An applet is a program run on the browser. It's seriously handicapped for good, in the sense you cannot read or write files or access memory on your machine. Maybe I shouldn't say it's handicapped cause an applet does what it's designed to do pretty well, though I hate it being sluggish.
Now that you say you want to connect to a database, that could be done using an application. So how does an application differ from an applet? An application can do far more than an applet could. First off, it can run as a separate entity and does not require a browser. Of course, it does require a JVM. Regarding the online-offline query, yes, an applet can be run only offline. i.e., it's downloaded to your machine and run. A java application can connect to computers, connect to databases, read/write files (in fact, the best thing I like about java is its variety of stream objects some of which you can use to manipulate files), etc. To connect to a database you can use JDBC.