Write a java program to accept the details of Doctor(Dname, DNo,Address,Salary) from user and insert it into the table, display it on the screen(use Command Line arguement).


import java.sql.*;


class d11

    {

     public static void main(String args[])

    {

     PreparedStatement pstmt;

     Connection con;

     ResultSet rs;


    try

    {

     if(args.length==0)

    {   

     System.out.println("pass the arguments");

    System.exit(0);

    }

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

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

    System.out.println("Connection establish");

    pstmt=con.prepareStatement("Insert into doctor1 values(?,?,?,?)");

    pstmt.setInt(1,Integer.parseInt(args[0]));

    pstmt.setString(2,args[1]);

    pstmt.setString(3,args[2]);

    pstmt.setInt(4,Integer.parseInt(args[3]));

    pstmt.executeUpdate();

    System.out.println(pstmt);

    System.out.println("Inserted record successfully");

    String sql="Select * from doctor1";

    pstmt=con.prepareStatement(sql);

    rs=pstmt.executeQuery();

    while(rs.next())

{    System.out.println("\n");

    System.out.println("\t"+rs.getInt(1));

    System.out.println("\t"+rs.getString(2));

    System.out.println("\t"+rs.getString(3));

    System.out.println("\t"+rs.getInt(4));

    }

    rs.close();

    con.close();

}    catch(Exception e)

{      e.printStackTrace();

    }}}
Write a java program to accept the details of Doctor(Dname, DNo,Address,Salary) from user and insert it into the table, display it on the screen(use Command Line arguement). Write a java program to accept the details of Doctor(Dname, DNo,Address,Salary) from user and insert it into the table, display it on the screen(use Command Line arguement). Reviewed by on April 27, 2015 Rating: 5
Powered by Blogger.