TY_BCA_2015_ADV_JAVA_15MARKS_SLIP9



SLIP 9:  Write a JDBC program to delete the records of employees whose names are starts with ‘A’character.

import java.sql.*;
class Slip9_1
{
            public static void main(String args[])
            {
                        Connection con;
                        Statement stmt;         
                        try
                        {
                                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                    con=DriverManager.getConnection("jdbc:odbc:dsn");
                                    if(con==null)
                                    {
                                                System.out.println("Connection Failed....");
                                                System.exit(1);
                                    }
                                    System.out.println("Connection Established...");

                                    stmt=con.createStatement();

                                    int no = stmt.executeUpdate("Delete from employee where name like 'A%'");
                                    if(no!=0)
                                                System.out.println("Delete Data sucessfully.....");
                                    else
                                                System.out.println("Data NOT Deleted");

                                    con.close();    
                        }          

                        catch(Exception e)
                        {
                                    System.out.println(e);
                        }
            }
}

No comments:

Post a Comment