Monday, April 11, 2011

A sea shore of Alibaug (Mandava Beach)

हा सागरी किनारा











Monday, April 4, 2011

JDBC Sample Code, Using DSN & MS-Access

import java.sql.*;
import java.io.*;

class Database
{
Connection con;
ResultSet rs;
Statement stmt;
BufferedReader br;
String str,temp;
Database()
{
try
{
con=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:ACCESS_DB");
stmt=con.createStatement();
str=new String();
temp=new String();
br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Connection Ok... Tested...");
}
catch(Exception E)
{
System.out.println("Connection Error : " + E.getMessage());
}
}
public void search()
{
System.out.println();
try
{
System.out.print("Enter string to be search : ");
str=br.readLine();
temp="Select * from Mobile Where Name Like '%" + str + "%' OR Num Like '%" + str + "%'";
System.out.println(temp);
rs=stmt.executeQuery(temp);
while(rs.next())
{
for(int i=1;i<=2;i++)
{
System.out.print(rs.getObject(i)+"\t");
}
System.out.println();
}
}
catch(Exception E)
{
System.out.println("SQL Error : " + E.getMessage());
}
}
public void add_new()
{
System.out.println();
String no,name;
try
{
System.out.print("Enter Mobile No : ");
no=br.readLine();
System.out.print("Enter Name : ");
name=br.readLine();
temp="Insert into Mobile Values('"+no+"','"+name+"')";
System.out.println(temp);
if(!stmt.execute(temp))
{
System.out.println("Record Successfully Inserted...");
}
else
{
System.out.println("Record Insertion failure...");
}
}
catch(Exception E)
{
System.out.println("SQL Error : " + E.getMessage());
}
}
public void select_all()
{
System.out.println();
try
{
rs=stmt.executeQuery("Select * from Mobile");
while(rs.next())
{
for(int i=1;i<=2;i++)
{
System.out.print(rs.getObject(i)+"\t");
}
System.out.println();
}
}
catch(Exception E)
{
System.out.println("SQL Error : " + E.getMessage());
}
}
public void con_close()
{
try
{
con.close();
}
catch(Exception E)
{
System.out.println("Connection Closing Error : " + E.getMessage());
}
}
public void update_record()
{
System.out.println("1.Search by Name");
System.out.println("1.Search by Number");
System.out.print("Enter your choice : ");
int ch1;
try
{
ch1=Integer.parseInt(br.readLine());
switch(ch1)
{
case 1:
System.out.print("Enter Name : ");
str=br.readLine();
System.out.print("Enter New Number : ");
temp="Update Mobile Set Num='"+br.readLine()+"' Where Name='"+str+"'";
System.out.println(temp);
if(!stmt.execute(temp))
{
System.out.println("Updation Successful...");
}
else
{
System.out.println("Updation Unsuccessful...");
}
break;

case 2:
System.out.print("Enter Number : ");
str=br.readLine();
System.out.println("Enter New Name : ");
temp="Update Mobile Set Name='"+br.readLine()+"' Where Num='"+str+"'";
System.out.println(temp);
if(!stmt.execute(temp))
{
System.out.println("Updation Successful...");
}
else
{
System.out.println("Updation Unsuccessful...");
}
break;

default:
System.out.println("Wrong Choice... Try Again...");
}
}
catch(Exception E)
{
System.out.println("Updation Error : "+E.getMessage());
}
}
public void delete_record()
{
System.out.println("1. Search by Name");
System.out.println("2. Search by Number");
System.out.print("Enter your choice : ");
int ch1;
try
{
ch1=Integer.parseInt(br.readLine());
switch(ch1)
{
case 1:
System.out.print("Enter Name to be deleted : ");
str=br.readLine();
temp="Delete From Mobile where Name='"+str+"'";
System.out.println(temp);
if(!stmt.execute(temp))
{
System.out.println("Deletion Successful...");
}
else
{
System.out.println("Deletion failure...");
}
break;

case 2:
System.out.print("Enter Number to be deleted : ");
str=br.readLine();
temp="Delete From Mobile where Num='"+str+"'";
System.out.println(temp);
if(!stmt.execute(temp))
{
System.out.println("Deletion Successful...");
}
else
{
System.out.println("Deletion failure...");
}
break;

default :
System.out.println("Wrong Choice...");
}
}
catch(Exception E)
{
System.out.println("Record Delection Error : " + E.getMessage());
}
}
}

public class DB_SAMPLE
{
public static void main(String args[])
{
Database db=new Database();
BufferedReader br;
int ch=0;
System.out.println("");
System.out.println("Mobile Contact Database for Personal Desktop Use");
System.out.println("");
System.out.println("");
System.out.println("1. See Entire Database");
System.out.println("2. Search");
System.out.println("3. Add new Record");
System.out.println("4. Delete");
System.out.println("5. Update");
System.out.print("Enter your Choice : ");
try
{
br=new BufferedReader(new InputStreamReader(System.in));
ch=Integer.parseInt(br.readLine());
}
catch(Exception E)
{
System.out.println("Console Reading Error : " + E.getMessage());
}

switch (ch)
{
case 1:
db.select_all();
break;

case 2:
db.search();
break;

case 3:
db.add_new();
break;

case 4:
db.delete_record();
break;

case 5:
db.update_record();
break;

default:
System.out.println("Wrong Choice... Try Again...");
}
db.con_close();
}
}

Friday, March 18, 2011

C++ problem

Hello Everybody I tried this code. Code gives 0 warning and 0 errors. I tested under Turbo C++ environment. My Question is How Constructor of all classes is called without creating an object? I know once constructor of class C is called it is automatically called upper class’s constructor. Basic question is how Constructor of class C is called with creating an object of that class?

**********CODE**********

#include<iostreams.h>

#include<conio.h>

#include<stdio.h>


class A

{

public :

A()

{

cout<<"A\n";

}

};


class B : public A

{

public :

B()

{

cout<<"B\n";

}

};


class C : public B

{

public :

C()

{

cout<<"C\n";

}

};


void main()

{

clrscr();

C();

getch();

}



**********OUTPUT**********


A

B

C

Sunday, February 27, 2011

FB chat as Text Message on your Mobile

Many times you may see my chat status is available. But mostly I m off-line. Your all IM send on my phone. So please understand this fact, if I am not replied on chat...

Now don't ask hows this possible. I m giving the answer.
Use yahoo messenger and register your mobile on it. And register your mobile for yahoo mobile contact. Then import all your facebook contact into that yahoo account. And done. You receive a text message from +5824119 or else.

*Tip :
1. This feature is available only for Yahoo India Messenger 11
2. You receive only 3 messages from a single contact at a single day...