int p=JOptionPane.showConfirmDialog(null,"Do U Want to Add","Add Product",JOptionPane.YES_NO_OPTION); if(p==0) { try { Class.forName("com.mysql.jdbc.Driver"); java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root"); java.sql.PreparedStatement pst1=con.prepareStatement("select * from inventory where Product_Code='"+jTextField2.getText()+"'"); ResultSet rs=pst1.executeQuery(); if(rs.next()) { JOptionPane.showMessageDialog(null,"Already Exists!!"); con.close(); ...