Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. private void btnAdd1ActionPerformed(java.awt.event.ActionEvent evt) {
  2. // TODO add your handling code here:
  3. Connection conn = null;
  4. Statement st = null;
  5. ResultSet rs = null;
  6.  
  7. try{
  8.  
  9. conn = DriverManager.getConnection("jdbc:mysql://localhost/check","root","");
  10. st = conn.createStatement();
  11.  
  12. String sql4 =("SELECT AVG(unit4) as num FROM lo where unit4 IS NOT NULL");
  13. PreparedStatement pstmt3 = conn.prepareStatement(sql4);
  14. ResultSet rs4 = pstmt3.executeQuery();
  15. rs4.next();
  16. double a3 = rs4.getDouble("num");
  17. double b3 = Math.round(a3*10);
  18. double res5 = b3/10;
  19. rs4.next();
  20. avg1.setText(String.valueOf(res5));
  21. String a1 =avg1.getText();
  22. String ans ;
  23.  
  24. if(a1.equals("0.0")){
  25. ans = null;
  26. }else{
  27. ans = a1;
  28. }
  29.  
  30. String query = "INSERT INTO chk(id) VALUES ('"+ans+"')";
  31. executeSQlQuery(query, "Inserted");
  32.  
  33. }
  34.  
  35. String query = "INSERT INTO chk(id) VALUES ('"+ans+"')";
  36.  
  37. String query = "INSERT INTO chk(id) VALUES ("+ ans +")";
  38.  
  39. if(ans != null)
  40. ans = "'" + ans + "'";
  41.  
  42. PreparedStatement ps = connection.prepareStatement("INSERT INTO chk(id) VALUES (?)");
  43. ps.setNull(1, java.sql.Types.VARCHAR);
  44. ps.executeUpdate();
  45.  
  46. if (rs4.next()) {//<<<--------------------
  47. double a3 = rs4.getDouble("num");
  48. //-----------^^-----------------
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement