Skip to main content

Posts

Showing posts from January, 2013

Java constructors-2

Constructors

A constructor is a special purpose java class method used for initializing a class object. While creating a constructor keep the following points in mind. 1. The name of the constructor is same as the class name. 2. There is no return type for a constructor. 3. A constructor invokes automatically when we create an object of that class. Suppose we have the following class and we need a constructor for that class. class MyClass { } Now i am going to create a constructor for the above class and is given bellow. class MyClass { MyClass            // Constructor { } } Example:  class MyClass { String demo; MyClass() { demo = "Demo value"; System.out.println("Constructor is invoked"); System.out.println("Assigned value is "+demo); } } public class ConstructorDemo { public static void main(String args[]) { MyClass m = new MyClass(); } } Output:

Java constructors- 1

SELECT Statement

The SELECT statement is used for accessing the contents of a table. Queries for using the SELECT statement is given bellow. SELECT * FROM table_name; The above SELECT query is used for displaying all the content of the table. '*'  indicates all content in that table. Example: SELECT * FROM Student; For the customized content view of a table use the following SELECT query. SELECT COLUMN_1, COLUMN_2........COLUMN_n  FROM TABLE_NAME; Example: SELECT name, address FROM Student; SELECT with WHERE clause  It is possible to access only a particular raw from a table using SELECT statement with the help of WHERE clause. Syntax: SELECT */COLUMN_NAMES FROM TABLE_NAME WHERE CONDITION; Example: From the Student table now i am going to access the details of 'prabeesh' only. I use the following query for it. SELECT * FROM Student WHERE name='prabeesh'; It is also note that the table contents are also not case sensitive. Here the table con

INSERT Statement

As the name suggested the INSERT statement help us to insert values to a table. SQ L queries for perform the INSERT operation are the following. If you want to insert values for the entire table, you can use the following query. INSERT INTO Table_Name VALUES(value_1, value_2,.........value_n); Example:               INSERT INTO Student VALUES('RESHMI', 'MAVELIKARA', 121, 350); It is note that the string values are always associated with single or double quotes. ( '' or "" ). The query execution in MySQL is shown bellow. If you don't want to insert the entire table, then you can use the following query. INSERT INTO Table_Name (column_1, column_2,..... column_n) VALUES (value_1, value_2,.........value_n); Example: If i want to insert values only for columns  name and address of table Student , then i use the following query. INSERT INTO Student (name, address) VALUES ('RUPESH', 'HARIPPAD');

CREATE Statement

The CREATE statement is used for creating a table in database. Syntax: CREATE TABLE Table_name (coloumn_1 datatype, coloumn_2 datatype,......coloumn_n datatype); Example: CREATE TABLE Student_Data (name varchar(40), Roll_No int, Address varchar(50)); Question: Create a table with name BANK and have the following fields Name Address Account_Number Balance_Amount, After creating table, display the structure of that table. ? Answer:  CREATE TABLE BANK (Name varchar(20), Address varchar(50), Account_Number int,         Balance_Amount int); execute the above query in MySQL is shown bellow In order to view the structure of the table use the following query. DESCRIBE Student; It is note that SQL is not case sensitive .