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!
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.jarin combination withconnector-api-1.5.jar, orjaybird-full-2.2.1.jar(which contains the classes from connector-api), because the driver cannot work without it.