/* ***************************************************************************** Copyright 2000 by Erica Andrews (cylikon@hotmail.com). All rights reserved. ./ButchWhipAppeal/ ./IcedPinky/ NO portion of this software may be used in ANY way by anyone other than myself without my express written consent. If it is downloaded for testing, it must be deleted from your system within 24 hours. Any other use constitutes piracy and fraudulent misuse of this software, punishable in a court of law. Copyright 2000 by Erica Andrews. All rights reserved. ***************************************************************************** */ package cylikon.ejb2; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import javax.ejb.*; import javax.naming.*; import java.rmi.*; import java.util.Properties; import sun.jdbc.rowset.*; import java.sql.*; import javax.sql.*; public class JdbcEJBClient2 extends Frame implements WindowListener,MouseListener { CachedRowSet crs; TextArea textscreen; Button doit; Label label; Panel panel1; Panel panel2; public JdbcEJBClient2 () { setTitle("MySQL Query Powered By Enterprise JavaBeans"); setLayout(null); setBackground(Color.cyan); setForeground(Color.black); setBounds(new Rectangle(5,5,790,570)); textscreen = new TextArea ( 5, 80 ); textscreen.setBackground(Color.blue); textscreen.setForeground(Color.white); textscreen.setBounds(new Rectangle(10,175,775,340)); doit = new Button("Show ALL Sites!"); doit.setForeground(Color.black); doit.setBackground(Color.pink); doit.addMouseListener( this ); doit.setBounds(new Rectangle(600,95,185,70)); label = new Label("MySQL Query Powered By Enterprise JavaBeans"); label.setAlignment(Label.CENTER); label.setForeground(Color.white); label.setBackground(Color.blue); label.setFont(new Font("Helvetica", Font.BOLD, 26)); label.setBounds(new Rectangle(2,25,790,60)); add (label); add (doit); add (textscreen ); addWindowListener ( this ); resize ( 790, 570); pack(); show (); } // end GUI constructor // ************** Listener Events ****************** //**** WindowListener methods public void windowActivated ( WindowEvent e ) { } public void windowDeactivated ( WindowEvent e ) { } public void windowOpened ( WindowEvent e ) { this.resize( 790, 570); } public void windowClosed ( WindowEvent e ) { } public void windowClosing ( WindowEvent e ) { this.hide (); this.dispose (); System.exit(0); } public void windowIconified ( WindowEvent e ) { } public void windowDeiconified ( WindowEvent e ) { } //**** MouseListener methods public void mouseClicked ( MouseEvent e ) { } public void mousePressed ( MouseEvent e ) { doit.setBackground(Color.red); label.setForeground(Color.red); label.setBackground(Color.white); label.setText("SEARCHING..."); } public void mouseReleased ( MouseEvent e ) { DoQuery(); } public void mouseEntered ( MouseEvent e ) { doit.setBackground(Color.green); } public void mouseExited ( MouseEvent e ) { doit.setBackground(Color.white); } /////////////////////////////// public static void main (String [] args) { new JdbcEJBClient(); } public void DoQuery() { try { System.out.print("Getting Initial Context..."); Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY,"org.ejboss.naming.spi.EjbossClientContextFactory"); Context ctx = new InitialContext(p); JdbcEJBHome home = (JdbcEJBHome) ctx.lookup("Jdbc EJB2"); JdbcEJB jdbc = home.create(); crs = new CachedRowSet(); // initialize the RowSet crs = jdbc.rset(); textscreen.appendText("Your Query found... \n\n"); int qcount = 0; // for counting queries // now unpack the CachedRowSet as we would any other ResultSet // This is a second method of handling the problem of serializing ResultSets collected // through JDBC queries. In my first example I used Vectors - not too difficult, but // it could get very messy with complex queries while (crs.next()) { String id = crs.getString(1).trim(); String itsgroup = crs.getString(2).trim(); String title = crs.getString(3).trim(); String url = crs.getString(4).trim(); String thedate = crs.getString(5).trim(); textscreen.appendText("ID: "+id+" GROUP: "+itsgroup+" TITLE: "+title+" URL: "+url+" DATE: "+thedate+"\n"); qcount++; } // end of while statement // now lets invoke the ResultSetCleanUp method to clear all rows from the // CachedRowSet crs.close(); // now, close the local ResultSet used by this client textscreen.appendText("\n\nYour query found "+qcount+" results."); } catch (Exception e) { textscreen.appendText("\n\nHouston we have a problem "+e+" "+e.getMessage());} } // end of method } // end of JdbcEJBClient Class