List:MySQL and Java« Previous MessageNext Message »
From:Christian Mack Date:June 14 1999 5:33pm
Subject:Re: Newbie applet and mm.mysql question...
View as plain text  
Richard Cannings wrote:
> 
> I'm trying to get my applet to do a simple SELECT query. I tried a few
> different ways which usually ended in:
> 
> SQLException: java.sql.SQLException: Error during query: null
> 
> Finally I gave up, downloaded Daniel Schneider's MySqlQueryApplet.java,
> edited it, and wouldn't you know-- yet another "SQLException:
> java.sql.SQLException: Error during query: null" error.
> 
> I searched the mailing list archive but couldn't find any information on
> this. I'm running mm.mysql.jdbc-1.2a, mysql-3.22.23b and
> jdk_1.1.7-v3-glibc-x86-native on a redhat-6.0 linux system. Also with
> the same login@server I can do the query no problem. Any advise would be
> appreciated.
> 
> Here is my editted source of Daniel Schneider's MySqlQueryApplet.java:
> 
> import org.gjt.mm.mysql.*;
> import org.gjt.mm.mysql.Connection;
> import org.gjt.mm.mysql.Statement;
> import org.gjt.mm.mysql.Driver;
> import org.gjt.mm.mysql.ResultSet;
> import java.applet.Applet;
> import java.awt.Graphics;
> import java.util.Vector;
> import java.sql.*;
> 
> public class MySqlQueryApplet 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();
>                   }
>     }
> 
>     /**
>      * The "run" method is called from the worker thread.  Notice that
>      * because this method is doing potentially slow databases accesses
>      * we avoid making it a synchronized method.
>      */
> 
>     public void run() {
>                   String url = "jdbc:mysql://ilaw.math.ucalgary.ca:3306/ilaw";
>                   // String url = "jdbc:mySubprotocol:myDataSource";
>                   String query = "select first_name, last_name from users_info";
> 
>                   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,"client_user"
>                                      , "_removed_");
>                                 Statement stmt = (Statement) con.createStatement();
>                                 ResultSet rs = (ResultSet)stmt.executeQuery(query);
>                                 while (rs.next()) {
>                                          String s = rs.getString("first_name");
>                                          String s2 = rs.getString("last_name");
>                                          String text = s + " " + s2;
>                                          results.addElement(text);
>                                 }
> 
>                                 stmt.close();
>                                 con.close();
> 
>                                 setResults(results);
> 
>                   } catch(SQLException ex) {
>                                 setError("SQLException: " + ex);
>                   }
>     }
> 
>     /**
>      * The "paint" method is called by AWT when it wants us to
>      * display our current state on the screen.
>      */
> 
>     public synchronized void paint(Graphics g) {
>                   // If there are no results available, display the current message.
>                   if (queryResults == null) {
>                                 g.drawString(message, 5, 50);
>                                 return;
>                   }
> 
>                   // Display the results.
>                   g.drawString("Who is in the database:  ", 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;
>                   }
>     }
> 
>     /**
>      * This private method is used to record an error message for
>      * later display.
>      */
> 
>     private synchronized void setError(String mess) {
>                   queryResults = null;
>                   message = mess;
>                   worker = null;
>                   // And ask AWT to repaint this applet.
>                   repaint();
>     }
> 
>     /**
>      * This private method is used to record the results of a query, for
>      * later display.
>      */
> 
>     private synchronized void setResults(Vector results) {
>                   queryResults = results;
>                   worker = null;
>                   // And ask AWT to repaint this applet.
>                   repaint();
>     }
> }

Hi Richard

What I can see, is that you load the mm JDBC-driver multiple times (I've never done this,
so perhaps your error comes from that).
Also, in a Applet you should load the JDBC driver with:
	Class.forName("org.gjt.mm.mysql.Driver").newInstance();
or with:
	DriverManager.registerDriver( new org.gjt.mm.mysql.Driver() );

If this isn't the problem, please send us a stacktrace of the error.

Tschau
Christian

Thread
Newbie applet and mm.mysql question...Richard Cannings14 Jun
  • Re: Newbie applet and mm.mysql question...Christian Mack14 Jun
  • Re: Newbie applet and mm.mysql question...Richard Cannings17 Jun
    • Re: Newbie applet and mm.mysql question...Hans Wolters17 Jun
  • Re: Newbie applet and mm.mysql question...Mark Matthew4 Jul