Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JButton;
- import javax.swing.JTextArea;
- import javax.swing.JPanel;
- import java.awt.event.ActionListener;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.awt.event.ActionEvent;
- public class Crud {
- private JFrame frame;
- Connection conn = null;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Crud window = new Crud();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public Crud() {
- initialize();
- conn = SqlConnect.dbConnect();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 795, 594);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- JLabel lblDatabaseCrudOperation = new JLabel("Database CRUD Operation Demo");
- lblDatabaseCrudOperation.setBounds(194, 0, 420, 26);
- frame.getContentPane().add(lblDatabaseCrudOperation);
- JTextArea textArea = new JTextArea();
- textArea.setBounds(0, 0, 304, 359);
- JPanel panel = new JPanel();
- panel.setBounds(444, 70, 304, 359);
- frame.getContentPane().add(panel);
- panel.setLayout(null);
- JTextArea textArea_1 = new JTextArea();
- textArea_1.setBounds(39, 70, 351, 366);
- frame.getContentPane().add(textArea_1);
- JButton btnLoad = new JButton("Load");
- btnLoad.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- String query = "Select * from Employee";
- PreparedStatement pst = conn.prepareStatement(query);
- ResultSet rs = pst.executeQuery();
- String display = "";
- while(rs.next()) {
- display += rs.getString("Fname")+ " ";
- display += rs.getString("Lname")+ " ";
- Integer age = rs.getInt("Age");
- display += rs.getInt("Age")+ " ";
- Double sal = rs.getDouble("Salary");
- //display += rs.getDouble("Salary")+ " ";
- display += sal.toString()+ " ";
- display += "\n";
- JOptionPane.showMessageDialog(null, display);
- }//end of while
- //textArea.setText(display);
- textArea_1.setText(display);
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
- });
- btnLoad.setBounds(509, 21, 141, 35);
- frame.getContentPane().add(btnLoad);
- //
- // JTextArea textArea_1 = new JTextArea();
- // textArea_1.setBounds(39, 70, 351, 366);
- // frame.getContentPane().add(textArea_1);
- // JPanel panel = new JPanel();
- // panel.setBounds(444, 70, 304, 359);
- // frame.getContentPane().add(panel);
- // panel.setLayout(null);
- //
- // JTextArea textArea = new JTextArea();
- // textArea.setBounds(0, 0, 304, 359);
- // panel.add(textArea);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement