Advertisement
Guest User

Untitled

a guest
Apr 15th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 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.  
  8. try{
  9.  
  10. conn = DriverManager.getConnection("jdbc:mysql://localhost/check","root","");
  11. st = conn.createStatement();
  12.  
  13.  
  14. String sql4 =("SELECT AVG(unit4) as num FROM lo where unit4 IS NOT NULL");
  15. PreparedStatement pstmt3 = conn.prepareStatement(sql4);
  16. ResultSet rs4 = pstmt3.executeQuery();
  17. rs4.next();
  18. double a3 = rs4.getDouble("num");
  19. double b3 = Math.round(a3*10);
  20. double res5 = b3/10;
  21. rs4.next();
  22. avg1.setText(String.valueOf(res5));
  23. String a1 =avg1.getText();
  24. String ans ;
  25.  
  26. if(a1.equals("0.0"))
  27. {
  28.  
  29. ans = null;
  30.  
  31.  
  32. }
  33.  
  34. else
  35. {
  36. ans = a1;
  37. }
  38.  
  39. String query = "INSERT INTO chk(id) VALUES ('"+ans+"')";
  40. executeSQlQuery(query, "Inserted");
  41.  
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement