애플릿이 있습니다. 이클립스에서 테스트 할 때 완벽하게 작동하지만 브라우저로 이동할 때 작동하지 않습니다.애플릿 애플릿 SQL INSERT가 브라우저에서 작동하지 않습니다.
애플릿이 더 이상 많이 사용되지는 않지만 이미 여러 가지 이유로 배울 점이 있습니다.
여기 내 코드입니다. 내가 말했듯이 이클립스에서 실행될 때 의도대로 작동합니다.
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;
}
}
설정해야 할 추가 브라우저 설정이 있습니까? 또한. SQL을 사용할 수 있도록 JDBC를 가져오고 있습니다. 어떻게 든 추가해야합니까?
브라우저에서와 같이 권한 예외가 발생할 수 있습니다. 애플릿은 보안 관리자로 실행됩니다. 사람들이보다 효과적으로 도움을 줄 수 있도록 어떤 예외를 지정해야합니까? – ipolevoy
1) Java 콘솔에서 오류를 확인하십시오. 2) DB가 애플릿과 동일한 서버에 있습니까? 3) AWT 기반 컴포넌트를이 천년기에 사용하지 말고 Swing을 사용하십시오. –
lol 팁 주셔서 감사합니다. 어떤 사람들은 브라우저 애플릿에서 AWT를 선호하지만 나는 이것을 스윙으로 바꿀 것이라고 읽었습니다. – Bullyen