Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import javax.swing.*;
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
- String query;
- try{
- Class.forName("java.sql.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mysql","root","admin");
- Statement stmt = con.createStatement();
- if(jRadioButton1.isSelected()){
- query = "select * from customers;";
- }
- else{
- String sq = jList1.getName();
- String cone = jComboBox1.getName();
- query = "select * from customers where "+ sq + " "+ cone + " ; " ;
- }
- ResultSet rs = stmt.executeQuery(query);
- while(rs.next()){
- String customerNumber = rs.getString("customerNumber");
- String customerName = rs.getString("customerName");
- String phone = rs.getString("phone");
- String address = rs.getString("addressLine1");
- String city = rs.getString("city");
- String state = rs.getString("state");
- String country = rs.getString("country");
- String creditlimit = rs.getString("Creditlimit");
- }
- rs.close();
- stmt.close();
- con.close();
- } catch(Exception e){
- JOptionPane.showMessageDialog(null, "Error in connectivity");
- }
- }
Add Comment
Please, Sign In to add comment