Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnAdd1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
- try{
- conn = DriverManager.getConnection("jdbc:mysql://localhost/check","root","");
- st = conn.createStatement();
- String sql4 =("SELECT AVG(unit4) as num FROM lo where unit4 IS NOT NULL");
- PreparedStatement pstmt3 = conn.prepareStatement(sql4);
- ResultSet rs4 = pstmt3.executeQuery();
- rs4.next();
- double a3 = rs4.getDouble("num");
- double b3 = Math.round(a3*10);
- double res5 = b3/10;
- rs4.next();
- avg1.setText(String.valueOf(res5));
- String a1 =avg1.getText();
- String ans ;
- if(a1.equals("0.0")){
- ans = null;
- }else{
- ans = a1;
- }
- String query = "INSERT INTO chk(id) VALUES ('"+ans+"')";
- executeSQlQuery(query, "Inserted");
- }
- String query = "INSERT INTO chk(id) VALUES ('"+ans+"')";
- String query = "INSERT INTO chk(id) VALUES ("+ ans +")";
- if(ans != null)
- ans = "'" + ans + "'";
- PreparedStatement ps = connection.prepareStatement("INSERT INTO chk(id) VALUES (?)");
- ps.setNull(1, java.sql.Types.VARCHAR);
- ps.executeUpdate();
- if (rs4.next()) {//<<<--------------------
- double a3 = rs4.getDouble("num");
- //-----------^^-----------------
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement