【发布时间】:2015-08-06 19:50:46
【问题描述】:
我正在制作一个基于表单的数据库,问题是我无法弄清楚数据库的表将如何使用我通过表单输入的数据进行更新。这是代码。
public New_Entry() {
initComponents();
}
private void pat_nameActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
@SuppressWarnings("UseSpecificCatch")
这是更新按钮的代码字符串......请帮我看看该怎么做......???
private void cmd_updateActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con;
String url ="jdbc:mysql://localhost:3306/testdb";
String user ="root";
String password ="";
con=(javaapplication5.Connection) DriverManager.getConnection(url,user,password);
Statement stmt= con.createStatement();
String Patient_ID=pat_id.getText();
String name=pat_name.getText();
String age=pat_age.getText();
String sex=pat_sex.getText();
String unit=pat_unit.getText();
String Diagonisis=diagonisis.getText();
String DateOfAddmission=DOA.getText();
String TreatmentPlan=treat_plan.getText();
String sql1 = "Insert into patient (Patient_ID,Name,Age,Unit,Sex,Diagonsis,DateOfAddmission,Treatment_Plan) values (?,?,?,?,?,?,?,?)";
stmt=con.prepareStatment(sql1);
stmt.executeUpdate(sql1);
pat_id.setText("");
pat_name.setText("");
pat_age.setText("");
pat_sex.setText("");
pat_unit.setText("");
diagonisis.setText("");
DOA.setText("");
treat_plan.setText("");
JOptionPane.showMessageDialog(null, " Record Updated!");
}
catch(Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
private void pat_ageActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void pat_unitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void DOAActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void pat_idActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void cmd_exitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);// TODO add your handling code here:
}
private void cmd_backActionPerformed(java.awt.event.ActionEvent evt) {
Start form = new Start();
New_Entry.this.setVisible(false);
form.setVisible(true);
}
private void cmd_newformActionPerformed(java.awt.event.ActionEvent evt) {
New_Entry frame2 = new New_Entry();
New_Entry.this.setVisible(false);
frame2.setVisible(true);
}
private void diagonisisActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
【问题讨论】: