dharmanshu

Orders

Dec 25th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 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 OrderNo = rs.getString("OrderNo");
  28. String ProductCode = rs.getString("ProductCode");
  29. String quantityOrdered = rs.getString("quantityOrdered");
  30. String priceEach = rs.getString("priceEach");
  31. String orderLineNumber = rs.getString("orderLineNumber");
  32. String reportto = rs.getString("reportto");
  33. String jobTitle = rs.getString("jobTitle");
  34. }
  35. rs.close();
  36. stmt.close();
  37. con.close();
  38. } catch(Exception e){
  39. JOptionPane.showMessageDialog(null, "Error in connectivity");
  40.  
  41. }
  42. }
Add Comment
Please, Sign In to add comment