Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.sql.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- class pg17setA1 extends JFrame implements ActionListener
- {
- JLabel l1;
- JTextArea ta;
- JButton b1,clear;
- Connection con;
- ResultSet rs;
- Statement st;
- JScrollPane p;
- public pg17setA1()
- {
- setLayout(new FlowLayout());
- ta=new JTextArea(5,30);
- b1=new JButton("Display");
- clear=new JButton("Clear");
- p=new JScrollPane(ta);
- add(p);
- add(b1);
- add(clear);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- b1.addActionListener(this);
- clear.addActionListener(this);
- setSize(500,500);
- setVisible(true);
- }
- public void actionPerformed(ActionEvent e)
- {
- try
- {
- Class.forName("org.postgresql.Driver");
- Connection con=DriverManager.getConnection("jdbc:postgresql://localhost:5432/rushya","postgres","");
- st=con.createStatement();
- rs=st.executeQuery("select * from student");
- while(rs.next())
- {
- ta.append(" "+rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3)+"\n");
- }
- }
- catch(Exception e5)
- {
- System.out.println("Exception found 5:"+e5);
- }
- }
- public static void main(String args[])
- {
- new pg17setA1();
- }
- }
Add Comment
Please, Sign In to add comment