我有一个小程序,当我在 Eclipse 中测试运行时它运行良好,但是当我进入浏览器时它似乎不起作用。
我已经读过小程序不再使用了,但出于各种原因我仍然想了解它们。
这是我的代码。就像我说的那样,它在 Eclipse 中运行时按预期工作。
public class WPStool extends Applet implements ActionListener
{
/**
*
*/
private static final long serialVersionUID = 6920052961843268403L;
Label lblCustNum, lblCustName, lblAccount, lblEmpID, lblSuccess;
TextField txtCustNum, txtCustName, txtAccount, txtEmpID;
Button bEnter;
boolean blnCorrect;
public void init()
{
lblCustNum = new Label("Customer #");
add(lblCustNum);
txtCustNum = new TextField(20);
add(txtCustNum);
lblCustName = new Label("Customer Name");
add(lblCustName);
txtCustName = new TextField(20);
add(txtCustName);
lblAccount = new Label("Account Type");
add(lblAccount);
txtAccount = new TextField(20);
add(txtAccount);
lblEmpID = new Label("EmployeeID");
add(lblEmpID);
txtEmpID = new TextField(20);
add(txtEmpID);
bEnter = new Button("Enter");
add(bEnter);
bEnter.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == bEnter)
{
//registerUser();
int custNum = Integer.parseInt(txtCustNum.getText());
int empID = Integer.parseInt(txtEmpID.getText());
enterInfo(custNum, txtCustName.getText(), txtAccount.getText(), empID);
txtCustNum.setText("");
txtCustName.setText("");
txtAccount.setText("");
txtEmpID.setText("");
}
}
public void enterInfo(int custNuma, String custNamea, String accounta, int empIDa)
{
Connection con = getConnection();
try
{
Statement s = con.createStatement();
String select = "INSERT INTO customerInfo (custNum , custName, account ,empID) VALUES ("+ custNuma +", '"+ custNamea +"', '"+ accounta +"', "+ empIDa +")";
//String select = "INSERT INTO customerInfo (custNum , custName, account ,empID) VALUES (123, 'Jim John Joe', 'New Account', 1234)";
s.executeUpdate(select);
lblSuccess = new Label("Success!");
add(lblSuccess);
}
catch (SQLException e)
{
System.out.println("getClasses method: " + e.getMessage());
lblSuccess = new Label("FAIL!");
add(lblSuccess);
}
}
private Connection getConnection()
{
Connection con = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/wps";
String user = "root";
String pw = "";
con = DriverManager.getConnection(url, user, pw);
}
catch (ClassNotFoundException e)
{
System.out.println("getConnection ClassNotFound: " + e.getMessage());
System.exit(0);
}
catch (SQLException e)
{
System.out.println("getConnection SQL: " + e.getMessage());
System.exit(0);
}
return con;
}
}
我需要设置一些额外的浏览器设置吗?还。我正在导入 JDBC,所以我可以使用 sql,我需要以某种方式添加它吗?