Write a java program to accept the details of Doctor(DNo,DName,Salary) from the user and insert it into the database(use prepared statement class and AWT).


import java.awt.*;

import java.sql.*;

import javax.swing.*;

import java.awt.event.*;


class cre

    {

     public static void main(String []args)

     {

     Frame f=new Frame();

     Label label1=new Label("D No:");

     Label label2=new Label("DName:");

     Label label3=new Label("Salary:");


    final TextField text1=new TextField(20);

    final TextField text2=new TextField(20);

    final TextField text3=new TextField(20);


    Button b=new Button("Save");

    b.addActionListener(new ActionListener()

    {

     public void actionPerformed(ActionEvent e)

     {

      int v1=Integer.parseInt(text1.getText());

      String v2=text2.getText();

      int v3=Integer.parseInt(text3.getText());

   

    try

      {

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

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

       String sql="insert into doctor(dno,dname,salary)values(?,?,?)";

       PreparedStatement pst=con.prepareStatement(sql);


      pst.setInt(1,v1);

      pst.setString(2,v2);

      pst.setInt(3,v3);

      pst.executeUpdate();

      JOptionPane.showMessageDialog(null,"Data is inserted successfully");

      }

    catch(Exception ex)

    { System.out.println(ex);

    }}});

    Panel p=new Panel(new GridLayout(5,2));

    p.add(label1);

    p.add(text1);

    p.add(label2);

    p.add(text2);

    p.add(label3);

    p.add(text3);

    p.add(b);

    f.add(p);

    f.setVisible(true);

    f.pack();

    }

}
Write a java program to accept the details of Doctor(DNo,DName,Salary) from the user and insert it into the database(use prepared statement class and AWT). Write a java program to accept the details of Doctor(DNo,DName,Salary) from the user and insert it into the database(use prepared statement class and AWT). Reviewed by on April 27, 2015 Rating: 5
Powered by Blogger.