samedi 20 février 2016

add row to sql table and close jdialog

I am trying to take all the data collected in the form and send it to my sql table then close the jdialog box. However, nothing is happening and my debug isn't showing any errors, so if figured i would let someone with skill check it out.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 
Object clas = jComboBox3.getSelectedItem();
String classi = clas.toString();

Object Cat = jComboBox1.getSelectedItem();
String categ = Cat.toString();

Object Cap = jComboBox2.getSelectedItem();
String capa = Cap.toString();

String Des = jTextArea1.getText();
String Jus = jTextArea2.getText();

Object rat = rate_def.getSelectedItem();
String rate = rat.toString();

Object Sc = Rating_Score.getValue();
int scor = (int) Sc;


String threat = "INSERT INTO InstThreats (Classification, Category, Capability, Description, Justification, Rating, Score) VALUES (?, ?, ?, ?, ?, ?, ?)";
try(Connection c = DriverManager.getConnection("jdbc:sqlite:MAAWB.db");
  Statement stmt = c.createStatement();){

  PreparedStatement preparedStmt = c.prepareStatement(threat);
  preparedStmt.setString    (2, classi);
  preparedStmt.setString    (3, categ);
  preparedStmt.setString    (4, capa);
  preparedStmt.setString    (5, Des);
  preparedStmt.setString    (6, Jus);
  preparedStmt.setString    (7, rate);
  preparedStmt.setInt    (8, scor);

  System.out.println(classi + categ + capa + Des + Jus + rate + scor);
  preparedStmt.executeUpdate();

  stmt.close();
  c.close();

} catch ( Exception e ) {
  System.err.println( e.getClass().getName() + ": " + e.getMessage() );
  System.exit(0);
}

Aucun commentaire:

Enregistrer un commentaire