0

Im developing an applet in eclipse, when executed from the eclipse's AppletViewer it works correctly but when executed from an .html file it dont execute class.forName() method.

here the .html

<!DOCTYPE html>
<html>
<body>

<p>Tarjetero.</p>

<applet 
codebase="classes"
code="ap.class"
width=234 height=274
archive="jaybird-full-2.2.0.jar">
</applet>

</body>
</html>

in the same folder I have all the created .class and jaybird .jar archive

here java files

ap.java

import javax.swing.JApplet;


public class ap extends JApplet {

/**
 * 
 */
private static final long serialVersionUID = 1L;

ui inter = new ui();

@Override
public void init() {
    // TODO Auto-generated method stub
    //JPanel p = new JPanel();
    //p.add(new JLabel("prueba"));
    inter.setVisible(true);
    this.add(inter);
}

@Override
public void start() {
    // TODO Auto-generated method stub
    super.start();
}

}

ui.java

import javax.swing.JPanel;


public class ui extends JPanel {

static JButton btnNewButton;
/**
 * 
 */
private static final long serialVersionUID = 1L;

/**
 * Create the panel.
 */
public ui() {
    setLayout(null);

     btnNewButton = new JButton("New button");

    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                btnNewButton.setText("1");
            ConexFirebird cf = new ConexFirebird();
            btnNewButton.setText("2");
            ResultSet rs = cf.EjecutarSentencia("SELECT nombre FROM CLIENTES;");
            btnNewButton.setText("3");


                if(rs.next())
                {
                    btnNewButton.setText("datos");
                }
                else
                {
                    btnNewButton.setText("nodatos");
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                btnNewButton.setText(e.getMessage());
                e.printStackTrace();
            }

        }
    });
    btnNewButton.setBounds(12, 12, 117, 24);
    add(btnNewButton);

    JRadioButton rdbtnNewRadioButton = new JRadioButton("New radio button");
    rdbtnNewRadioButton.setBounds(8, 44, 149, 22);
    add(rdbtnNewRadioButton);

    JCheckBox chckbxNewCheckBox = new JCheckBox("New check box");
    chckbxNewCheckBox.setBounds(18, 70, 129, 22);
    add(chckbxNewCheckBox);

}
}

conexFirebird.java

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.*;
import javax.swing.JOptionPane;


/**
*
* @author Jose
*/
public class ConexFirebird {
// static File directorio= new File("//");
//static String DireccionBD="jdbc:firebirdsql:192.168.47.254/3050:/BBDD/ArenasTiradoJoseMTarjetero.fdb";
static String DireccionBD="jdbc:firebirdsql:localhost/3050:/var/lib/firebird/2.5/data/tarjetavisitas.fdb";
static String Usuario="sysdba";
//static String Contrasena="persiza";
String Contrasena="masterkey";

static String NombreDriver="org.firebirdsql.jdbc.FBDriver";

static Connection Conexion;
static Statement Consulta;
static ResultSet Resultado;

public ConexFirebird()
{
        try
    {

            ui.btnNewButton.setText("10");
       Class.forName(NombreDriver) ;
       ui.btnNewButton.setText("11");
       Conexion = DriverManager.getConnection(DireccionBD, Usuario, Contrasena);           
       ui.btnNewButton.setText("12");
       Consulta = Conexion.createStatement();
       ui.btnNewButton.setText("13");


    }
    catch (ClassNotFoundException e) {
        // TODO: handle exception
        ui.btnNewButton.setText("classNfound");
    }
    catch(Exception e)
    {
        ui.btnNewButton.setText("23");
        JOptionPane.showMessageDialog(null, e.getMessage());

    }
}

public void EjecutarInsert(String Sentencia)
{
    try {
        Consulta.execute(Sentencia);
        JOptionPane.showMessageDialog(null, "Guardado correctamente", "Guardado", JOptionPane.INFORMATION_MESSAGE);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        JOptionPane.showMessageDialog(null, "Ese DNI ya se encuentra en la base de datos", "Error", JOptionPane.INFORMATION_MESSAGE);
    }
}


public ResultSet EjecutarSentencia(String Sentencia)
{
    try
    {
    Resultado = Consulta.executeQuery(Sentencia);
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, e.getMessage()+"ejecutar sentencia");
    }

    return Resultado;
}


public void EjecutarUpdate(String Sentencia) throws SQLException
{
   try
    {
    Consulta.executeUpdate(Sentencia);


    }
    catch(SQLException e)
    {

        //JOptionPane.showMessageDialog(null, e.getMessage());
        throw new SQLException("");

    } 
}

public void CerrarConexion()
{
    try
    {
    Consulta.close();
    }
    catch(Exception e)
    {

    }
}

public void insertarConBlob(String nombre, String dni, String correo, File fD, File fA)
{
    try {
        PreparedStatement ps;
        if(fD != null && fA != null)
        {
            ps = Conexion.prepareStatement("INSERT INTO CLIENTES (ID, NOMBRE, DNI, CORREO, FOTODELANTE, FOTODETRAS ) VALUES ( gen_id(id_clientes, 1), '"+nombre+"', '"+dni+"', '"+correo+"', ?, ?)");
            try{
            ps.setBlob(1, new FileInputStream(fD));
            ps.setBlob(2, new FileInputStream(fA));
            ps.execute();
            JOptionPane.showMessageDialog(null, "Guardado correctamente", "Guardado", JOptionPane.INFORMATION_MESSAGE);
            }
            catch(FileNotFoundException e)
            {
                JOptionPane.showMessageDialog(null, "No se encontro el archivo", "Error", JOptionPane.INFORMATION_MESSAGE);
            }
            catch(SQLException e)
            {
                JOptionPane.showMessageDialog(null, "Ese DNI ya se encuentra en la base de datos", "Error", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        else if (fD != null)
        {
            ps = Conexion.prepareStatement("INSERT INTO CLIENTES (NOMBRE, DNI, CORREO, FOTODELANTE) VALUES ( '"+nombre+"', '"+dni+"', '"+correo+"', ?)");
            try{
            ps.setBlob(1, new FileInputStream(fD));
            ps.execute();
            }
            catch(FileNotFoundException e)
            {
                JOptionPane.showMessageDialog(null, "No se encontro el archivo", "Error", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        else if (fA != null)
        {
            ps = Conexion.prepareStatement("INSERT INTO CLIENTES (NOMBRE, DNI, CORREO, FOTODETRAS) VALUES ( '"+nombre+"', '"+dni+"', '"+correo+"', ?)");
            try{
            ps.setBlob(1, new FileInputStream(fA));
            ps.execute();
            }
            catch(FileNotFoundException e)
            {
                JOptionPane.showMessageDialog(null, "No se encontro el archivo", "Error", JOptionPane.INFORMATION_MESSAGE);
            }
        }






    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

I know all these java files can be improved. I have to use that button label changing to debug because I CANT find the console in iceweasel

OS: Debian Browser: Iceweasel java jdk 1.6 jaybird 2.2.0

Thanks in advance, all you need to answer the question just ask for it! thanks!

J. Arenas
  • 493
  • 1
  • 9
  • 23
  • Can you open the java console. There are no visible errors? . Because of the restrictive limitations of applets, you can not access a file and any directory of your choice. Inside Eclipse, try it without the path only `tarjetavisitas.fdb` in the url. If that works it will work in an Applet. – moskito-x Oct 04 '12 at 19:13
  • Now is giving a ClassNotFoundException in class.forName() method I think its about not finding the jaybird jar, There was a mistake I meant i CANT open the java console I think there is no more support for that – J. Arenas Oct 04 '12 at 19:17
  • extract the whole jar content to the folder where your app.class is. After that there will also be a folder `org`. Now remove 'archive="jaybird-full-2.2.0.jar"` from the applet code. Runs that in eclipse? – moskito-x Oct 04 '12 at 19:33
  • that didn't work with the .html file – J. Arenas Oct 04 '12 at 19:53
  • I think you have the required files, not in the directory "www/htdocs/myapp" (whatever point to your server webroot) – moskito-x Oct 04 '12 at 20:12
  • When I change the name or path and execute the applet, I go to the apache error.log and appears that the required file doesn't exists so now is correct – J. Arenas Oct 04 '12 at 20:20
  • You should neither path nor file names change, but put all the necessary files to the server and remove in the .html file, only the reference to the .jar file. The structure of the folder on the webserver should look : folders: `translation javax org` files: `ap.class *.class myap.html` – moskito-x Oct 04 '12 at 20:43
  • I think you dont understood me, I mean that using the path im using right now i dont get any errors in the apache error.log but if I change them I get the file doesnt exists so i think paths are corrects, in the server folder I have .html file and a folder 'classes' with all the classes and the jaybird .jar file, the html file is slightly different from the beggining file, I have changed it in question – J. Arenas Oct 04 '12 at 20:58

2 Answers2

2

Jaybird was not designed with Applets in mind, as far as I know it will generate an error (when run in the browser) because it tries to read a system property. It will work in AppletViewer as that - afaik - runs with all permissions.

See also:

Also make sure that you use jaybird-2.2.1.jar in combination with connector-api-1.5.jar, or jaybird-full-2.2.1.jar (which contains the classes from connector-api), because the driver cannot work without it.

Community
  • 1
  • 1
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • I signed the jar and change to jaybird-full-2.2.1.jar and still the same problem, but thanks for the help!!, I will mark your answer as valid – J. Arenas Oct 05 '12 at 17:59
  • A stacktrace would be helpful to pin it down – Mark Rotteveel Oct 05 '12 at 18:59
  • I can't get a stackTrace because it is in the browser where it crashes and I can't get the console, I tried JConsole to attach to IcedTea plugin but it can't, I will try it and paste it here if I finally get it – J. Arenas Oct 06 '12 at 10:12
  • I finally managed to connect JConsole to the icedTea plugin but i dont know how to get the stack Trace from the ocurred exception, Any tips? – J. Arenas Oct 06 '12 at 10:40
  • I haven't used JConsole a lot, so I don't really know. – Mark Rotteveel Oct 06 '12 at 10:59
1

Your start code should be like this

<APPLET 
    codebase="classes" 
    code="ap.class" 
    width=234 height=274 
    archive="jaybird-full-2.2.0.jar">
</APPLET>
Sergii Zagriichuk
  • 5,389
  • 5
  • 28
  • 45
  • That link is for Platform(s): Windows 7, Vista, Windows XP, Windows 2000 and I'm using debian – J. Arenas Oct 04 '12 at 19:38
  • I get ClassnotFoundException in class.forName("org.firebirdsql.jdbc.FBDriver"); I dont think it's about permissions because there is a java.policy.applet with this content /* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/ /* DO NOT EDIT */ grant { permission java.security.AllPermission; }; – J. Arenas Oct 04 '12 at 19:44
  • On Linux it's early just run Java Control Panel(for ubuntu http://askubuntu.com/questions/65600/how-to-show-java-plugin-console like example) and all other the same – Sergii Zagriichuk Oct 04 '12 at 19:56
  • I've put example how your applet script should be written, just copy and try – Sergii Zagriichuk Oct 04 '12 at 19:56
  • 1
    @J.Arenas BTW, you have to enable console and push errors here. – Sergii Zagriichuk Oct 04 '12 at 19:59
  • I'm using openjdk-6 and IcedTea plugin for iceweasel and i think that don't have the console – J. Arenas Oct 04 '12 at 20:19
  • Can it be that jaybird doesn't support Applets? Its only a thought – J. Arenas Oct 04 '12 at 20:21
  • @J.Arenas :) it is imposible, firstly you written that ALL IS WORKING on AppletViewer secondly it is not support by Applet, where is logic ? IcedTea has logs, just looks to your home ~/.icedtea folder, read this mails http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2009-February/004909.html – Sergii Zagriichuk Oct 04 '12 at 20:28