JDBC Tutorial


Computer Questions for CSE students


 Dear viewers,I  arranged a programming Exam  contest 

The selection procedure depends on-
  • Time of your answers submission
  • Correctness of your given answers.

To win a prize attempt the following question answers.


Exam - I
I. Answer the following questions. [10]
1. Write the use of the function while(). Give one example.
2. Write the function of for loop. Give one example.
3. Explain the use of conditional operator with the help of an example.
4. Why the if( ) statement is known as a conditional control statement? Explain your answer with the help of an example.
5. Why do……while( ) statement is known as “Enter looping” statement? Explain your answer with the help of an example.
II. Fill in the blanks. [10]
1. ----------- symbol is used as unsigned right shift operator.
2. & is used for -------------------------- .
3. ------------------ Symbol is used for bit wise XOR.
4. The symbol , (comma) is used as ------------------------- .
5. << symbol is used as --------------------------- .
6. If int a = 23 and b = 7 then the value of a % b is --------------.
6. -------------- is the symbol for ternary operator .
7. If int a = 5 , int b = 2 and int c = a / b . then value of c is ----------------.
8. If x = 3 and x = (++ x) + (x++) then value of x after evaluation is -------- .
9. If a = 34 , b = 23 and int k = (34 > 23)? a : b ; then value of k is ------.
10. The symbol ( ~ ) is used for --------------------- 


The prize will be sent to your mobile phone as a flexi load/balance transfer.

Contestant must submit their answers with cell number [for Bangladeshi contestant only] 
Send your answer only to this email: ahmmad.cse@gmail.com

Data Update task of DBMS

An SQL UPDATE statement changes the data of one or more records in a table. Either all the rows can be updated, or a subset may be chosen using a condition.
The UPDATE statement has the following form

UPDATE table_name SET column_name = value [, column_name = value ...] [WHERE condition]
For the UPDATE to be successful, the user must have data manipulation privileges (UPDATE privilege) on the table or column, the updated value must not conflict with all the applicable constraints (such as primary keys, unique indexes, CHECK constraints, and NOT NULL constraints).
In some databases, as PostgreSQL, when a FROM clause is present, what essentially happens is that the target table is joined to the tables mentioned in the fromlist, and each output row of the join represents an update operation for the target table. When using FROM you should ensure that the join produces at most one output row for each row to be modified. In other words, a target row shouldn't join to more than one row from the other table(s). If it does, then only one of the join rows will be used to update the target row, but which one will be used is not readily predictable.
Because of this indeterminacy, referencing other tables only within sub-selects is safer, though often harder to read and slower than using a join.

Examples

Set the value of column C1 in table T to 1, only in those rows where the value of column C2 is "a".
UPDATE T SET C1 = 1 WHERE C2 = 'a'
In table T, set the value of column C1 to 9 and the value of C3 to 4 for all rows for which the value of column C2 is "a".
UPDATE T SET C1 = 9, C3 = 4 WHERE C2 = 'a'
Increase value of column C1 by 1 if the value in column C2 is "a".
UPDATE T SET C1 = C1 + 1 WHERE C2 = 'a'
Prepend the value in column C1 with the string "text" if the value in column C2 is "a".
UPDATE T SET C1 = 'text' || C1 WHERE C2 = 'a'
Set the value of column C1 in table T1 to 2, only if the value of column C2 is found in the sub list of values in column C3 in table T2 having the column C4 equal to 0.
UPDATE T1 
SET    C1 = 2    
WHERE  C2 IN ( SELECT C3
               FROM   T2
               WHERE  C4 = 0)
You may also update multiple columns in a single update statement:
UPDATE T SET C1 = 1, C2 = 2
Complex conditions and JOINs are also possible:
UPDATE T SET A = 1 WHERE C1 = 1 AND C2 = 2
UPDATE a
SET a.[updated_column] = updatevalue
FROM articles a 
JOIN classification c 
ON a.articleID = c.articleID 
WHERE c.classID = 1
Or on Oracle-systems
UPDATE (
SELECT *
  FROM articles a 
  JOIN classification c 
    ON a.articleID = c.articleID 
) AS a
SET a.[updated_column] = updatevalue
WHERE c.classID = 1

References

http://dev.mysql.com/doc/refman/5.0/en/update.html  http://www.postgresql.org/docs/8.1/static/sql-update.html

An election is contested by 5 caddidates.The candidates are numbered 1 to 5 and the voting is done by marking the candidate number on the ballot paper.Write a program to read the ballots and count the votes cast for each candidate using an array variable count.In case, a number read is outside the range 1 to 5,the ballot should be considered as a ‘spoilt’ and the program should also count the number of spoilt ballots


import java.io.*;
class election
{
            public static void main(String args[])throws
            IOException
            {
                        DataInputStream in = new
                        DataInputStream(System.in);

                        int i,n,a=0,spoilt=0;
                        System.out.print("Enter number of ballots: ");
                        n = Integer.parseInt(in.readLine());
                        System.out.println();
                        int count[] = new int[n];
                        for(i=0;i

                        {
                                    System.out.print("Enter Vote: ");
                                    count[i] = Integer.parseInt(in.readLine());
                        if( count[i] == 1 || count[i] == 2 || count[i] == 3 || count[i] == 4 || count[i] ==5)
                                    a++;
                                    else
                                    {
                                                System.out.println("\t\tOutside the range");
                                                spoilt++;
                                    }
                         }
                        System.out.println("bollte paper: " + a);
                        System.out.println("spoilt parep: " + spoilt);
    }
}

Write a program to read the data and determine the following (a)Total marks obtained by each student.(b)The highest marks in each subject and the roll no.of the student who secured it(c)the student obtained the highest total marks

import java.io.*;
class StudentResult
{

int result[][]=new int[100][5];
int i,j,k,total,maxr,maxm;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void takeData() throws IOException
{
for(i=0;i< 100;i++)
{
total=0; for(j=0;j< 4;j++)
{
if(j==0)
System.out.println("Enter Roll number\t");
else if(j==1)
System.out.println ("Enter 1st subject marks\t");
else if(j==2)
System.out.println ("Enter 2nd subject marks\t");
else if(j==3)
System.out.println ("Enter 3rd subject marks\t");
result[i][j]=Integer.parseInt(br.readLine());
if(j!=0) total+=result[i][j];
}
result[i][j]=total;
}
}
public void showResult()
{
System.out.println ("Mark sheet");
System.out.println ("\nRoll 1st 2nd 3rd Total");
for(i=0;i<100;i++)
{
for(j=0;j< 5;j++)
{
System.out.println (" "+result[i][j]);
}
System.out.println ();
}
System.out.println ("\n\n");
System.out.println ("Roll number with total");
System.out.println("\nRoll Total");
for(i=0;i<100;i++)
{
for(j=0;j<5;j++)
{
if((j==0)||(j==4))
System.out.println (" "+result[i][j]);
}
System.out.println ();
}
for(i=1;i< 4;i++)
{
for(j=0;j< 100;j++)
{
if(j==0)
{
maxm=result[j][i]; maxr=result[j][0];
}
else if(result[j][i]>maxm)
{
maxm=result[j][i];
maxr=result[j][0];
}
}
if(i==1)
System.out.println ("\nMaximum marks in sub1 is :"+maxm + ""+maxr);
else if(i==2)
System.out.println ("\nMaximum marks in sub2 is :"+maxm + " "+maxr);
else if(i==3)
System.out.println ("\nMaximum marks in sub3 is :"+maxm + " "+maxr);
}
for(i=0;i< 100;i++)
{
for(j=0;j< 5;j++)
{
if(j==4)
{
if(i==0)
{
maxm=result[i][j]; maxr=result[i][0];
}
else if(result[i][j]>maxm)
{
maxm=result[i][j];
maxr=result[i][0];
}
}
}
}
System.out.println ("\nMaximum total is :"+maxm + " "+maxr);
}
}

#### What is HTML?Hyper Text Markup Language


HTML is a computer language devised to allow website creation. These websites can then be viewed by anyone else connected to the Internet. It is relatively easy to learn, with the basics being accessible to most people in one sitting; and quite powerful in what it allows you to create. The definition of HTML is Hyper Text Markup Language.
  • Hyper Text is the method by which you move around on the web — by clicking on special text called hyperlinks which bring you to the next page. The fact that it is hyper just means it is not linear — i.e. you can go to any place on the Internet whenever you want by clicking on links — there is no set order to do things in.
  • Markup is what HTML tags do to the text inside them. They mark it as a certain type of text (italicized  text, for example).
  • HTML is a Language, as it has code-words and syntax like any other language.

How does it work?

HTML consists of a series of short codes typed into a text-file by the site author — these are the tags. The text is then saved as a html file, and viewed through a browser, like Internet Explorer or Netscape Navigator. This browser reads the file and translates the text into a visible form, hopefully rendering the page as the author had intended. Writing your own HTML entails using tags correctly to create your vision. You can use anything from a rudimentary text-editor to a powerful graphical editor to create HTML pages.

Why is Java known as platform-neutral language?

Plateform neutral or platform independence, means that programs written in the Java language must run similarly on any supported hardware/operating-system platform. A programmer should be able to write a program one time, compile it one time, and then be able to execute it anywhere; holding true to the Sun Microsystems slogan, "Write Once, Run Anywhere. "ava was designed to not only be cross-platform in source form like C, but also in compiled binary form. Since this is frankly impossible across processor architectures Java is compiled to an intermediate form called byte-code. A Java program never really executes natively on the host machine. Rather a special native program called the Java interpreter reads the byte code and executes the corresponding native machine instructions. Thus to port Java programs to a new platform all that is needed is to port the interpreter and some of the library routines. Even the compiler is written in Java. The byte codes are precisely defined, and remain the same on all platforms.


Java is used in many facets, from the digital displays on our microwaves and refrigerators in our kitchen to the digital displays on our telephones, fax machines, and copiers in our office. It is used on the web (via applets

A least five major C++ features that were intentionally removed from JAVA


C++ Features Not Found in Java
C++ supports multiple inheritance of method implementations from more than one superclass at a time. While this seems like a useful feature, it actually introduces many complexities to the language. The Java language designers chose to avoid the added complexity by using interfaces instead. Thus, a class in Java can inherit method implementations only from a single superclass, but it can inherit method declarations from any number of interfaces. 

C++ supports templates that allow, for example, to implement a Stack class and then instantiate it as Stack or Stack to produce two separate types: a stack of integers and a stack of floating-point values. Java does not allow this, but efforts are underway to add this feature to the language in a robust and standardized way. Furthermore, the fact that every class in Java is a subclass of Object means that every object can be cast to an instance of Object. Thus, in Java it is often sufficient to define a data structure (such as a Stack class) that operates on Object values; the objects can be cast back to their actual types whenever necessary.

C++ allows to  define operators that perform arbitrary operations on instances of  our classes. In effect, it allows to extend the syntax of the language. This is a nifty feature, called operator overloading, that makes for elegant examples. In practice, however, it tends to make code quite difficult to understand. After much debate, the Java language designers decided to omit such operator overloading from the language. Note, though, that the use of the + operator for string concatenation in Java is at least reminiscent of operator overloading. 

C++ allows to define conversion functions for a class that automatically invoke an appropriate constructor method when a value is assigned to a variable of that class. This is simply a syntactic shortcut (similar to overriding the assignment operator) and is not included in Java. 

In C++, objects are manipulated by value by default; we must use & to specify a variable or function argument automatically manipulated by reference. In Java, all objects are manipulated by reference, so there is no need for this & syntax.

A least ten major different between C and JAVA

No preprocessor
Java does not include a preprocessor and does not define any analogs of the #define, #include, and #ifdef directives. Constant definitions are replaced with staticfinal fields in Java.Macro definitions are not available in Java, but advanced compiler technology and inlining has made them less useful. Java does not require an #include directive because Java has no header files. Java class files contain both the class API and the class implementation, and the compiler reads API information from class files as necessary. Java lacks any form of conditional compilation, but its cross-platform portability means that this feature is very rarely needed.
No global variables
Java defines a very clean namespace. Packages contain classes, classes contain fields and methods, and methods contain local variables. But there are no global variables in Java, and, thus, there is no possibility of namespace collisions among those variables.
Well-defined primitive type sizes
All the primitive types in Java have well-defined sizes. In C, the size of short, int, and long types is platform-dependent, which hampers portability.
No pointers
Java classes and arrays are reference types, and references to objects and arrays are akin to pointers in C. Unlike C pointers, however, references in Java are entirely opaque. There is no way to convert a reference to a primitive type, and a reference cannot be incremented or decremented. There is no address-of operator like &, dereference operator like * or −>, or sizeof operator. Pointers are a notorious source of bugs. Eliminating them simplifies the language and makes Java programs more robust and secure.
Garbage collection
The Java Virtual Machine performs garbage collection so that Java programmers do not have to explicitly manage the memory used by all objects and arrays. This feature eliminates another entire category of common bugs and all but eliminates memory leaks from Java programs.
No goto statement
Java doesn't support a goto statement. Use of goto except in certain well-defined circumstances is regarded as poor programming practice. Java adds exception handling and labeled break and continue statements to the flow-control statements offered by C. These are a good substitute for goto.
Variable declarations anywhere
C requires local variable declarations to be made at the beginning of a method or block, while Java allows them anywhere in a method or block. Many programmers prefer to keep all their variable declarations grouped together at the top of a method, however.
Forward references
The Java compiler is smarter than the C compiler, in that it allows methods to be invoked before they are defined. This eliminates the need to declare functions in a header file before defining them in a program file, as is done in C.


Method overloading
Java programs can define multiple methods with the same name, as long as the methods have different parameter lists.
No struct and union types
Java doesn't support C struct and union types. A Java class can be thought of as an enhanced struct, however.
No enumerated types
Java doesn't support the enum keyword used in C to define types that consist of fixed sets of named values. This is surprising for a strongly typed language like Java, but there are ways to simulate this feature with object constants.
No bitfields
Java doesn't support the (infrequently used) ability of C to specify the number of individual bits occupied by fields of a struct.
No typedef
Java doesn't support the typedef keyword used in C to define aliases for type names. Java's lack of pointers makes its type-naming scheme simpler and more consistent than C's, however, so many of the common uses of typedef are not really necessary in Java.
No method pointers
C allows to store the address of a function in a variable and pass this function pointer to other functions. We cannot do this with Java methods, but we can often achieve similar results by passing an object that implements a particular interface. Also, a Java method can be represented and invoked through a java.lang.reflect.Method object.
No variable-length argument lists
Java doesn't allow to define methods such as C's printf() that take a variable number of arguments. Method overloading allows to simulate C varargs functions for simple cases, but there's no general replacement for this feature.

JAVA to MS Access Connection (JDBC-ODBC bridge)

Java program for condition check within two numbers

import javax.swing.JOptionPane;
class Addition1
{
      public static void main(String args[])
       {
         String result="";

          String fN;

             String sN;

                int n1,n2;

      fN=JOptionPane.showInputDialog("Enter the first number");
      sN=JOptionPane.showInputDialog("Enter the second number");
      n1=Integer.parseInt(fN);
      n2=Integer.parseInt(sN);
    if(n1==n2)
      result=result+n1+"=="+n2;
    if(n1>=n2)
       result=result+"\n"+n1+">="+n2;
    if(n1<=n2)
       result=result+"\n"+n1+"<="+n2;
    if(n1!=n2)
       result=result+"\n"+n1+"!="+n2;
    if(n1
       result=result+"\n"+n1+"<"+n2;
    if(n1>n2)
       result=result+"\n"+n1+">"+n2;
    JOptionPane.showMessageDialog(null,result);
     }
}