Sunday, 21 October 2012

insertion program of data in JAVA



class insert
{
    public static void main(String[] argv)
    {
        try
        {
            Scanner sc=new Scanner(System.in);
            String name,roll,dob;
            int tot;
         
         
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            String database="jdbc:odbc:eceDSN";
            Connection con=DriverManager.getConnection(database,"","");
            System.out.println("eceDSN is Connected");
            System.out.println("Enter The Roll No");
            roll=sc.nextLine();
            System.out.println("Enter The Name");
            name=sc.nextLine();
            System.out.println("Enter The Total");
            tot=sc.nextInt();
            sc.nextLine();
            System.out.println("Enter The DOB");
            dob=sc.nextLine();
            String query="insert into ECE values('"+roll+"','"+name+"','"+tot+"','"+dob+"')";
            //create a statement object
            Statement st=con.createStatement();
            //Execute the statement
            int result=st.executeUpdate(query);
            if(result==1)
            {
                System.out.println("Record is Inserted Successfully");
            }
            con.close();
        }
            catch(Exception err)
            {
                System.out.println(err.getMessage());
            }
            //loading all the driver to the memory
     
    }
}

No comments:

Post a Comment

Tech N Science © 2013