dharmanshu

ConsumerList

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