Guest User

Untitled

a guest
Dec 3rd, 2017
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import java.util.*;
  2. import java.sql.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import javax.swing.*;
  6.  
  7. class pg17setA1 extends JFrame implements ActionListener
  8. {
  9. JLabel l1;
  10. JTextArea ta;
  11. JButton b1,clear;
  12. Connection con;
  13. ResultSet rs;
  14. Statement st;
  15. JScrollPane p;
  16. public pg17setA1()
  17. {
  18. setLayout(new FlowLayout());
  19. ta=new JTextArea(5,30);
  20. b1=new JButton("Display");
  21. clear=new JButton("Clear");
  22. p=new JScrollPane(ta);
  23. add(p);
  24. add(b1);
  25. add(clear);
  26. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  27. b1.addActionListener(this);
  28. clear.addActionListener(this);
  29. setSize(500,500);
  30. setVisible(true);
  31. }
  32. public void actionPerformed(ActionEvent e)
  33. {
  34. try
  35. {
  36. Class.forName("org.postgresql.Driver");
  37. Connection con=DriverManager.getConnection("jdbc:postgresql://localhost:5432/rushya","postgres","");
  38. st=con.createStatement();
  39. rs=st.executeQuery("select * from student");
  40. while(rs.next())
  41. {
  42. ta.append(" "+rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3)+"\n");
  43. }
  44. }
  45. catch(Exception e5)
  46. {
  47. System.out.println("Exception found 5:"+e5);
  48. }
  49. }
  50. public static void main(String args[])
  51. {
  52. new pg17setA1();
  53. }
  54. }
Add Comment
Please, Sign In to add comment