dharmanshu

Products

Dec 25th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1.  
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.Statement;
  6. import javax.swing.JOptionPane;
  7.  
  8. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  9. String query;
  10. try{
  11. Class.forName("java.sql.Driver");
  12. Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mysql","root","admin");
  13. Statement stmt = con.createStatement();
  14. if(jRadioButton1.isSelected()){
  15. query = "select * from customers;";
  16.  
  17. }
  18. else{
  19. String sq = jList1.getName();
  20. String cone = jComboBox1.getName();
  21. query = "select * from customers where " + sq+" " + cone + " ;" ;
  22. }
  23. ResultSet rs = stmt.executeQuery(query);
  24.  
  25.  
  26. while(rs.next()){
  27. String productCode = rs.getString("productCode");
  28. String productName = rs.getString("productName");
  29. String vendor = rs.getString("vendor");
  30. String description = rs.getString("description");
  31. String buyPrice = rs.getString("buyPrice");
  32.  
  33. }
  34. rs.close();
  35. stmt.close();
  36. con.close();
  37. } catch(Exception e){
  38. JOptionPane.showMessageDialog(null, "Error in connectivity");
  39.  
  40. }
  41. }
Add Comment
Please, Sign In to add comment