我有以下UI 我不能插入到數據庫MSACCESS
但後來,我不能插入任何數據到ms access database
。手動生成的第一行通過ms access database
我不知道什麼是我的代碼這件事,似乎他們都做得很好
private void doSimpan(String idnya, String namanya,String alamatnya,String teleponnya,String emailnya,String passwordnya,String rolesnya) {
try {
String query = "INSERT INTO MsEmployee (EmployeeID, EmployeeName, EmployeeAddress, EmployeePhone, EmployeeEmail, EmployeePassword, EmployeeRole)VALUES ('"+idnya+"','"+namanya+"','"+alamatnya+"','"+teleponnya+"','"+emailnya+"','"+passwordnya+"','"+rolesnya+"')";
connect.executeQuery(query);
fillTable();
cmd.printSuccess("Master Employee", namanya+" saved successfully");
} catch (Exception e) {
}
}
這裏是execQuery
方法
private statement st;
public void executeQuery(String query)
{
try {
st.executeUpdate(query);
} catch (SQLException ex) {
System.out.println("Error: " +ex);
}
}
這裏是我的printAsk()
方法
public Boolean printAsk(String title, String text)
{
if(JOptionPane.showConfirmDialog(null, text, title, JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
return true;
}
else
{
return false;
}
}
這裏是我的isValid()
方法
private Boolean isValid(String name,String address,String phone,String email,String password) {
if(name.equals("") || address.equals("") || phone.equals("") || email.equals("") || password.equals(""))
{
return false;
}
else if(val.isNumeric(phone) || !email.contains("@") && !email.endsWith(".com"))
{
return false;
}
else
{
return true;
}
}
這裏是代碼我save button
//save
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
String idnya = jTextField1.getText();
String namanya = jTextField2.getText();
String alamatnya = jTextArea1.getText();
String teleponnya = jTextField3.getText();
String emailnya = jTextField4.getText();
String passwordnya = new String(jPasswordField1.getPassword());
String rolesnya = jComboBox2.getSelectedItem().toString();
if(status==1) //to insert
{
if(isValid(namanya, idnya, teleponnya, emailnya, passwordnya))
{
if(cmd.printAsk("Master Employee", namanya+" will be entered, continue ?"))
{
doSimpan(idnya, namanya, alamatnya, teleponnya, emailnya, passwordnya, rolesnya);
fillTable();
defaultControl(false,false);
crudButton(true);
}
}
else
{
cmd.printFail("Master Employee", "all field must be filled");
}
}
else if (status==2)//to update
{
}
}
做我出問題在哪裏? 我得到了「nencor保存成功」但後來,我無法找到MS Access數據庫
我Connect
構造函數命名nencor
任何員工
public Connect() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=TIFProject.mdb");
st = con.createStatement(1004, 1008);
} catch (Exception ex) {
System.out.println("Database Error" + ex);
}
}
1)使用一個真正的數據庫,該橋式驅動器的不支持,並已上了十年去。 2)檢查你的自動提交設置,這種問題的常見原因。 – jwenting