Hallo,
ich arbeite mit der Entwicklungsumgebung eclipse und habe mir dort eine neues Projekt mit einem Apple angelegt. Dort habe ich die "mysql-connector-java-5.1.18-bin.jar" als Library eingefügt..alles kein Problem. Ich greife mit meinem Applet auf die lokale Datenbank vom meinem Xampp zu. Wenn ich aber jetzt das Projekt (alle dateien + index.html) kopiere und z.B. in die Xampp Server reinmache oder sonst nicht über eclipse, bekomme ich die Meldung, das der Treiber nicht gefunden wurde.
Hier mal mein Code von der MySQL-Klasse:
dann hier mal der Code meines Applet:
und dann falls interessant auch die index.html:
Ich habe da einen Label auf meinem Applet der mir jeh nach Exception nen einfachen Fehler ausgibt. Er findet bei mir den Treiber nur wenn ich mein Applet über eclpise debugge. Was muss ich nun machen, damit das Applet auch auf meinem WebSpace funktioniert.
Danke im Voraus.
ich arbeite mit der Entwicklungsumgebung eclipse und habe mir dort eine neues Projekt mit einem Apple angelegt. Dort habe ich die "mysql-connector-java-5.1.18-bin.jar" als Library eingefügt..alles kein Problem. Ich greife mit meinem Applet auf die lokale Datenbank vom meinem Xampp zu. Wenn ich aber jetzt das Projekt (alle dateien + index.html) kopiere und z.B. in die Xampp Server reinmache oder sonst nicht über eclipse, bekomme ich die Meldung, das der Treiber nicht gefunden wurde.
Hier mal mein Code von der MySQL-Klasse:
Java:
import java.sql.*;
public class MySQL
{
private Connection conn = null;
private String username;
private String password;
private String port;
private String host;
private String database;
public static String Error = null;
public MySQL(String username, String password, String database, String host, String port)
{
this.username = username;
this.password = password;
this.host = host;
this.port = port;
this.database = database;
try
{
Class.forName("com.mysql.jdbc.Driver");//.newInstance();
conn = DriverManager.getConnection("jdbc:mysql://"+this.host+":"+this.port+"/"+this.database+"?user="+this.username+"&password="+this.password);
Error = "Verbindung erfolgreich";
}
catch(ClassNotFoundException classE)
{
Error = "Treiber nicht gefunden.";
classE.printStackTrace();
}
catch(SQLException sqlE)
{
Error = "Verbindung nicht möglich.";
}
catch(Exception e)
{
Error = "Driver not found.";
}
}
public User[] GetUsers()
{
User[] users = new User[5];
if(conn != null)
{
Statement query;
try
{
query = conn.createStatement();
String sql = "SELECT * FROM user";
ResultSet result = query.executeQuery(sql);
int i = 0;
while(result.next())
{
users[i] = new User();
users[i].Id = result.getString("id");
users[i].Username = result.getString("name");
users[i].Code = result.getString("code");
users[i].Admin = GetTrueOrFalse(Integer.parseInt(result.getString("admin")));
users[i].State = GetTrueOrFalse(Integer.parseInt(result.getString("aktiv")));
users[i].Email = result.getString("e_mail");
users[i].IP = result.getString("ip_adress");
i++;
Error = "Alles okay :D";
}
return users;
}
catch(SQLException sqlE)
{
Error = "Shitt ;D";
return users;
}
}
return users;
}
private Boolean GetTrueOrFalse(int zahl)
{
if(zahl == 1)
{
return true;
}
return false;
}
}
dann hier mal der Code meines Applet:
Java:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Administration extends JApplet
{
public Administration() {
}
private static final long serialVersionUID = 1L;
private JTabbedPane TabCollection = new JTabbedPane();
private JLabel lblShit;
private MySQL mysql = null;
// initialize components
public void init()
{
setSize(500, 300);
SetTabs();
SpringLayout springLayout = new SpringLayout();
JMenuBar menuBar = new JMenuBar();
springLayout.putConstraint(SpringLayout.EAST, TabCollection, 0, SpringLayout.EAST, menuBar);
springLayout.putConstraint(SpringLayout.NORTH, TabCollection, 6, SpringLayout.SOUTH, menuBar);
springLayout.putConstraint(SpringLayout.WEST, TabCollection, 0, SpringLayout.WEST, getContentPane());
springLayout.putConstraint(SpringLayout.SOUTH, TabCollection, 300, SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.WEST, menuBar, 0, SpringLayout.WEST, getContentPane());
springLayout.putConstraint(SpringLayout.EAST, menuBar, 0, SpringLayout.EAST, getContentPane());
springLayout.putConstraint(SpringLayout.NORTH, menuBar, 0, SpringLayout.NORTH, getContentPane());
getContentPane().setLayout(springLayout);
getContentPane().add(menuBar);
JMenu MenuStart = new JMenu("Start");
menuBar.add(MenuStart);
JMenuItem StartItem = new JMenuItem("Start");
ActionStart(StartItem, 0);
MenuStart.add(StartItem);
JMenu EinstellungenChildMenu = new JMenu("Einstellungen");
MenuStart.add(EinstellungenChildMenu);
JMenuItem UserItem = new JMenuItem("Benutzer bearbeiten");
ActionEditUser(UserItem, 1);
EinstellungenChildMenu.add(UserItem);
JMenu MenuInfo = new JMenu("Info");
menuBar.add(MenuInfo);
JMenuItem HelpItem = new JMenuItem("Help");
MenuInfo.add(HelpItem);
JMenuItem AboutItem = new JMenuItem("About");
MenuInfo.add(AboutItem);
mysql = new MySQL("root", "", "db_1", "localhost", "3306");
lblShit.setText(MySQL.Error);
}
private void SetTabs()
{
JPanel Users = new JPanel();
JPanel EditUser = new JPanel();
JPanel Admins = new JPanel();
// Add Tab to TabCollection
TabCollection.addTab("Benutzer", Users);
SpringLayout sl_Users = new SpringLayout();
Users.setLayout(sl_Users);
lblShit = new JLabel("Shit");
sl_Users.putConstraint(SpringLayout.NORTH, lblShit, 10, SpringLayout.NORTH, Users);
sl_Users.putConstraint(SpringLayout.WEST, lblShit, 10, SpringLayout.WEST, Users);
sl_Users.putConstraint(SpringLayout.EAST, lblShit, 485, SpringLayout.WEST, Users);
Users.add(lblShit);
TabCollection.addTab("Benutzer bearbeiten", EditUser);
TabCollection.addTab("Admins", Admins);
// Change Event
TabCollection.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
TabCollection.getSelectedIndex();
}
});
// Add Tabs
getContentPane().add(TabCollection);
}
/*
* All Event-Handlers!
* ----------------------------------------------
*/
private void ActionStart(JMenuItem menuItem, final int selectIdex)
{
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
//getAppletContext().showDocument(getDocumentBase(), "_self");
TabCollection.setSelectedIndex(selectIdex);
}
});
}
private void ActionEditUser(JMenuItem menuItem, final int selectIdex)
{
menuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
User[] users = mysql.GetUsers();
lblShit.setText(users[0].Username + MySQL.Error);
//TabCollection.setSelectedIndex(selectIdex);
}
});
}
}
und dann falls interessant auch die index.html:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
<applet width="500" height="300" code="Administration.class" style="border:solid 1px #000" />
</body>
</html>
Ich habe da einen Label auf meinem Applet der mir jeh nach Exception nen einfachen Fehler ausgibt. Er findet bei mir den Treiber nur wenn ich mein Applet über eclpise debugge. Was muss ich nun machen, damit das Applet auch auf meinem WebSpace funktioniert.
Danke im Voraus.