Write a java program to display the record of Doctor (DNo,DName,Salary) from the database and display it in the screen( use JTable).


import javax.swing.*;

import java.awt.*;

import java.io.*;

import java.sql.*;

class slip3 extends JFrame

    {

     String[]dname=new String[10];

     int[]dno=new int[10];

     int[]salary=new int[10];

     int no=0;

     Connection con=null;

     Statement state=null;

     Object[][]data=new Object[10][10];

     public slip3()

    {

     try

    {

     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

     con=DriverManager.getConnection("jdbc:odbc:my1dsn.dsn");

     System.out.println("Statement object is created");

      state=con.createStatement();

     String[]doc={"Doctor no","Doctor Name","Salary"};

     ResultSet rs=state.executeQuery("select * from doctor");

     while(rs.next())

    {

     dno[no]=rs.getInt(1);

     dname[no]=rs.getString(2);

     salary[no]=rs.getInt(3);

     no++;

     }

    for(int i=0;i    {
    data[i][0]=dno[i];
    data[i][1]=dname[i];
    data[i][2]=salary[i];
    }
    JTable doctor=new JTable(data,doc);
    JScrollPane jsp=new JScrollPane(doctor);
    add(jsp);
    rs.close();
    con.close();
    state.close();
    }
    catch(Exception e)
    {
JOptionPane.showMessageDialog(null,""+e,"slip3",JOptionPane.INFORMATION_MESSAGE);
    }
    setVisible(true);
    setSize(200,200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new FlowLayout());
    }
    public static void main(String args[])
    {
     new slip3();
    }
}
Write a java program to display the record of Doctor (DNo,DName,Salary) from the database and display it in the screen( use JTable). Write a java program to display the record of Doctor (DNo,DName,Salary) from the database and display it in the screen( use JTable). Reviewed by on April 27, 2015 Rating: 5
Powered by Blogger.