You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dana Marcusanu <dm...@yahoo.com> on 2001/04/25 03:20:08 UTC

Database applets - help

Hi, 
I was wondering if you can help me. I am using Tomcat 3.2.1, MM.MYSQL
2.0.4 and MySQL database. I am trying to access data from the database by
using the following applet:
import java.sql.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.Vector;

public class exa extends Applet {

    private Statement stat;
    private Button b1;
    private String message = "Alles Ok";
    private String message2, message3;
    private int x, y;
    private Vector results;

    public void init () {
        x = 5;
        y = 90;
        b1 = new Button("Search");
        b1.addActionListener(new ClickHandler());
        add(b1);
        try {
	    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
            System.out.println("Driver loaded");
            message = "Driver loaded";
            repaint();
        }
        catch (Exception e) {
            System.out.println("Driver not loaded");
            e.printStackTrace();
            message = "Driver not loaded";
            repaint();
        }
    }

    public void start() {
        String url = "jdbc:mysql://129.1.66.14:3306/test1";
        String query = "Select * from people";
        try {
            Connection conn = DriverManager.getConnection(url);
            stat = conn.createStatement();
            ResultSet rs = stat.executeQuery(query);
            while (rs.next()) {
                String voor = rs.getString(1);
                results.addElement(voor);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            message2 = "connection error";
            repaint();
        }
    }

    public void paint (Graphics g) {
        g.drawString(message, 5, 50);
        if (message2 != null) {
            g.drawString(message2, 5, 70);
        }
        if (message3 != null) {
            g.drawString(message2, x, y);
        }
    }

    class ClickHandler implements ActionListener {
        public void actionPerformed (ActionEvent e) {
            int index = 1;
            message3 = results.elementAt(index).toString();
            repaint();
        }
    }
}

I got connection error and I don't know how to fix it. Any suggestion will
be welcome.

Thanks, Dana Marcusanu 

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/