Write a JDBC program to remove “percentage” column from student (rno, sname, percentage) table

import java.io.*;
import java.sql.*;
public class RemoveColumn
{           static Connection cn;
            static Statement st;
            static ResultSet rs;
            public static void main(String args[])
            {           try{
                                    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                    cn=DriverManager.getConnection("jdbc:odbc:dsn","","");
                                    st=cn.createStatement();
                                    rs=st.executeQuery("select * from student");
                                    while(rs.next())
                                    {
                        System.out.println(rs.getInt("rno")+"\t"+rs.getString("sname")+"\t"+rs.getInt("percentage"));                               }
                                    String str="alter table student drop column percentage";
                                    st.executeUpdate(str);
                                    System.out.println("Column is remove");
                                    rs=st.executeQuery("select * from student");
                                    while(rs.next()) {
                                                                     System.out.println(rs.getInt("rno")+"\t"+rs.getString("sname"));
                                                                  }
                                    cn.close();      
                        }catch(Exception e){
                                                               System.out.println(e);
                                                           }
            }
}

Comments

Popular posts from this blog

Write a java program to create Teacher table(TNo.TName, Sal, Desg) and insert a record in it.

Create a JSP page to accept a number from an user and display it in words: Example: 123 – One Two Three. The output should be in red color.

Write a JSP program to accept the details of Account (ANo, Type, Bal) and store it into database and display it in tabular form. (Use PreparedStatement interface)