import java.applet.Applet;import java.awt.Graphics;import java.util.Vector;import java.sql.*; public class lokal_applet2 extends Applet implements Runnable { private Thread worker; private Vector queryResults; private String message = "Initializing"; public synchronized void start() { // Every time "start" is called we create a worker thread to re-evaluate the database query. if (worker == null) { message = "Connecting to database"; worker = new Thread(this); worker.start(); } } public void run() { String url = "jdbc:mysql://localhost:3306/javatest"; String query = "select * from mitarbeiter"; try { Class.forName("org.gjt.mm.mysql.Driver"); } catch(Exception ex) { setError("Can't find Database driver class: " + ex); return; } try { Vector results = new Vector(); Connection con = (Connection) DriverManager.getConnection(url,"", ""); Statement stmt = (Statement) con.createStatement(); ResultSet rs = (ResultSet) stmt.executeQuery(query); while (rs.next()) { String s = rs.getString("name"); String s1 = rs.getString("vorname"); String text = s + " " + s1; results.addElement(text); } stmt.close(); con.close(); setResults(results); } catch(SQLException ex) { setError("SQLException: " + ex); } } public synchronized void paint(Graphics g) { if (queryResults == null) { g.drawString(message, 5, 50); return; } g.drawString("Name: ", 5, 10); int y = 30; java.util.Enumeration enum = queryResults.elements(); while (enum.hasMoreElements()) { String text = (String)enum.nextElement(); g.drawString(text, 5, y); y = y + 15; } } private synchronized void setError(String mess) { queryResults = null; message = mess; worker = null; repaint(); } private synchronized void setResults(Vector results) { queryResults = results; worker = null; repaint(); }}