JavaApplet MySQL JDBC Tutorial Using Netbeans

Java Applet is a Java Program that can be embedded in HTML documents. Usually, we use an applet viewer  to show the result of our program. For java applet, we must create an HTML documents that specifies which applet class to execute. We will learn by making the applet class and making the simple HTML code that can embed our program.

This time, I only use the simple JApplet program, just to make sure that in Applet we can also make a connection to MySQL Database. 🙂

In this Tutorial, we will use 2 class that we have created in past tutorial, and

First, make sure that the webserver has been started. I use XAMPP 1.6.6a, and I use the database that we’ve made in the past JDBC tutorial.

Then, Create your java library Project from Netbeans :


After that, add the MySQL JDBC :



Then add a class named, for this tutorial I use This class in functioned as an Applet. The content is look like this :

import javax.swing.JApplet;
import javax.swing.JOptionPane;
import java.awt.Graphics;
 * @author ferdiansyah.dolot
public class Welcome extends JApplet{
    String connection = "";
    String insertion ="";
    public void init(){

            Connect c = new Connect();
            connection = "Connection Established";
            Sqlstatement s = new Sqlstatement();
            insertion = "Success";
        catch(Exception e){
            connection="Connection Failed";
    public void paint(Graphics g){

Samples method that we use in applet program above are  init ()  and paint(Graphics g). The applet container first called init() method when applet is loaded for exection, after that paint(Graphics g) method is executed. More about JavaApplet you can read here : . The two method init() and paint(Graphics g) are JApplet life-cycle method that are called by an applet container during an applet’s execution. About JApplet life-cycle you can read them here :

After making the Applet class, then we must make the HTML file to specify which applet class we use. The simple HTML code is look like this :

<applet code=”Welcome.class” width=”250″ height=”80″></applet>

In HTML above, we specify the width of applet viewer is 250 and the height is 80, and we use Welcome class. Save this HTML document in the same folder of src in your Netbeans Project folder (example : …\NetBeansProjects\Project1\src), put the HTML code in src folder.

After that, run the Welcome class in Netbeans, then it works.


Then’ It’s possible to use applet with JDBC. 🙂

Thanks for reading.

Past Tutorial to find the Java Past Program that we use in this tutorial :

Java MySQL JDBC Tutorial Using Netbeans Part 2

Java MySQL JDBC Tutorial Using Netbeans Part 1


7 thoughts on “JavaApplet MySQL JDBC Tutorial Using Netbeans

  1. udah run yg welcome..kan kalo sukses biasanya udah langsung kebentuk class.nya….tp ga ada..liat class di netbeans dimananya…???
    udah di run.. ga muncul yang applet gitu…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s