Official Site

click here to view our new site launched

Pages

Sunday, May 12, 2013

Free web hosting sites



Although the modern Internet community is moving towards social networks and clouds, there is still some space for traditional free web hosting that enables to publish a custom web page, or custom blog, or other “manually” build website on the web at absolutely no cost.
In this article we provide an overview of the most desirable and the best free web hosting features as well as suggest top 10 free web hosting providers that in our opinion offer the best free hosting services in terms of offered features and customer support.
Free web hosting no ads stands for a web host service or provider that does not add any adverts (banners, pop-ups, text links, etc.) to free web pages and website that they host for free.
Free domain hosting stands for webhost services or providers that enable clients to host their own domain names (registered at 3rd party domain registration service) on webhost’s servers at no additional cost.
And free domain hosting can also refer to website hosts services that provide a free domain nameincluded with their free webhosting plan.
Free PHP MySQL hosting stands for the web page hosting service or provider that offers the popular PHP scripting and MySQL database support included with their free website hosting plan.
In regards to the best free hosts, we can suggest to check the following list of the top 10 free hosting providers that we’d recommend to consider using to host your free web site, weblog, community forums, image gallery, etc.:
  1. Biz.nf (PHP, MySQL, WordPress, Joomla, Free .co.nf domain, No ads)
  2. Free Hosting EU (Blog / Site builder, No ads, Free .eu.pn domain)
  3. AwardSpace.net (PHP, MySQL, Email Sending, No Ads, Free subdomain)
  4. Biz.ly (Website & Blog builder, Photo album, Free .biz.ly domain)
  5. FreeHostia.com (PHP, MySQL, 1-click Scripts, No Ads, Free subdomain)
  6. Wix.com (Easy Flash website builder + mobile sites, blogs, etc.)
  7. ByetHost.com (PHP, MySQL, PHPbb, SMF, Wiki, Free subdomain)
  8. x10Hosting.com (Support cPanel, PHP, FTP, No ads, Free subdomain)
  9. Serversfree.com (Php,Mysql,Wordpress,and more)
  10. Webs.com (Easy site builder, blog, forms, polls, Free subdomain)
and also see visitor’s reviews of best free website hosting providers.

Almost Free Web Hosting

And in case you’d like to host your lovely website with much more reliable and customer focused web hosting provider that a free web host can not afford, and if you do not mind to pay few dollars for the advanced service, you might be interested to consider the following website hosting providers that offer quite cheap (almost free hosting) service:
Free Hosting
  1. HostGator
  2. iPage
  3. JustHost
and also you can take a look at top 10 web hosting list at PRchecker.info site.

Thursday, March 21, 2013

Command Line Mac Os

On Mac OS X (and Linux), vi is symlinked to vim (vi improved), a more modern free software version. Vim It is the default editor when changing a crontab.

Vi has two modes, command and insert (really, three if you count replace mode). Command mode is used to navigate, search, and issue other commands. Insert mode is used to enter text.

While in command mode (case sensitive)

move the cursor with arrow keys; if there aren't any arrow keys, use j,k,h,l

i - change to insert mode (before cursor)
a - change to insert mode (after cursor)
A - change to insert mode (at end of line)
r - replace one character
R - overwrite text
x - delete one character
dd - delete one line
yy - yank line (copy)
p - paste deleted or yanked text after cursor
P - paste deleted or yanked text before cursor
G - go to end of the file
1G - go to top of the file
J - merge next line with this one
/ - search, follow / with text to find
:wq - write file and quit
:q! - quit without saving
%s/old/new/g - substitute; replace "old" with "new" on all lines
:g/pattern/d - delete all lines that match the pattern

While in insert mode

ESC - change to command mode
any text typed is entered at the cursor

Typical vi session

Type "vi file.txt" at command prompt
Move cursor to where new text will be added
Type "i" to change to insert mode
Type new text
Type ESC to go back to command mode
type ":wq" and ENTER to write the file and quit



Support us at Sync4Brain

Monday, March 4, 2013

How to Get Facebook,G+,Twitter Like for an Url in PHP


You need the call the bellow functions to get value:

  • call get_plusones($url)  to get G+ count
  • call get_likes($url) to get Facebook Likes count
  • call get_tweets($url) to get Count of tweet for the url

function get_plusones($url) {

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS,
 '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
    $curl_results = curl_exec($curl);
    curl_close($curl);
    $json = json_decode($curl_results, true);
    return intval($json[0]['result']['metadata']['globalCounts']['count']);
}

function get_likes($url) {

    $json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);
    $json = json_decode($json_string, true);

    return intval( $json[$url]['shares'] );
}

function get_tweets($url) {
    $json_string = file_get_contents("http://urls.api.twitter.com/1/urls/count.json?url=$url");
    $json = json_decode($json_string, true);

    return intval($json['count']);
}

Saturday, March 2, 2013

YouTube Videos Download Trick

Download YOU-TUBE videos on your computer or mobile without any software

Follow this Very simple trick:

Go to YouTube, Open the video that you want to download
  1. Now you have to make a small change in video link [ Replace "www." to "ss"] For example http://www.youtube.com/watch?v=EWnNyT3QTSQ http://ssyoutube.com/watch?v=EWnNyT3QTSQ
  2. After it will redirect to a new site http://en.savefrom.net/
  3. Now you have to choose the format of the video like mp4,3gp,flv and also shows the video quality like 240p,360p,720p,1080p

Sunday, February 24, 2013

File Permissions Made Easy - Command Line

Checking File Permission

ls -lart filename
or
ls -l filename

The file permissions can be displayed using the command:
% ls -l [filename]
For example, to display the permissions on the file myfile.txt, type the command:
% ls -l myfile.txt
-rw-r--r-- 1  lnp5jb  777  Dec 22  myfile.txt

Changing File Permissions

The easiest way is the symbolic method, which lets you specify access classes and types with single letter abbreviations.

chmod modes

In the command:
% chmod mode filename
the mode consists of three elements:
who
operator
permissions
The following options are possible:

who:

u user (owner)
g group
o other
a all

operators:

- remove permission
+ add permission
= assign permission

permissions:

r read
w write
x execute


For example:

  • to add permission for everyone to read a file in the current directory named myfile, at the Terminal , The  stands for "all", the  +  for "add", and the  r  for "read". you would enter: 
    • chmod a+r myfile
  • removes read and write permissions from others.
    • chmod o-rw file1.f
  • adds execute permission to the owner.
    • chmod u+x test

Saturday, February 16, 2013

Simple & Fun Trick of Computer

Let your computer speaks whatever you type:
 Folks, with this cool trick you create a small tool where you can type and convert in to voice. The process is very easy. All you have to do is : 
  •  Open notepad and paste the following code 
Dim message, sapi
message=InputBox("hello from csehackerz, Do you want your computer to speak?","Csehackerz Updates")
Set sapi=CreateObject("sapi.spvoice")
sapi.Speak message 
  • Then click file, then click save as and choose any name and .vbs extension. For notepad the usual extension is .txt , so you have to change .txt extension to .vbs. For example , JSC.vbs 
  • That's it! Double click on the icon and box will pop up. Type whatever you want listen and click ok. The computer will speak the sentence you type in the box. 

Isn't it a cool trick? 
  • Notepad Trick
    • Open notepad and type .LOG in capital letters and press ENTER. You can record the exact date and time by using this trick.
  • Reserved Keyword Trick
    • Do you know that it is not possible make a folder with the name "con”? No matter how many times you try to make a folder with the name "Con", you won't be able to do it.The reason: Con is a "reserved keyword" used by DOS, so you can't create a folder with that keyword. However, there is a way to create a folder with the name “CON”. To do this, go to the command prompt and type "MD \\.\E:\CON” . This will create a folder named CON in the E drive of your Computer.
  • Strange Font
    • Open your notepad and increase the font size to 72, then change the font to Windings. Afterwards, type your name in capital letters. You’ll be surprised to see some peculiar symbols!
  • Desktop Wallpaper Prank
    • Take a screen shot of your desktop and then open the image and set it as your desktop background. Now, hide all the icons from your desktop. Also, unlock the task-bar. Now your desktop will look exactly the same as before, but all of the icons will not be clickable! This trick could easily confuse anyone and is a fun trick to play on some friends.
  • Microsoft Word Trick
    • Simply open up Microsoft Word and type =Rand (200, 99), then press enter. Hopefully you enjoy the magic!

Monday, May 21, 2012

Database helper class in Android


import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Database{
SQLiteDatabase db;
String DB_NAME="test.db";
String root="data/data/com.example.test/";
 
String DB_FULL_PATH=root+"databases/"+DB_NAME;
int Rcount=0;
public void CreateDB(Activity a) {
 
        this.db = a.openOrCreateDatabase(
        DB_NAME
      , SQLiteDatabase.CREATE_IF_NECESSARY
      , null
      );
       
       
        db.setVersion(1);
        db.setLocale(Locale.getDefault());
        db.setLockingEnabled(true);
       
}
 
public void OpenDB(Activity a) {
 
this.db = SQLiteDatabase.openDatabase(DB_FULL_PATH, null,
                SQLiteDatabase.OPEN_READWRITE);
       
}
 
 public void CloseDB(Activity a) { 
this.db.close();       
}

public boolean checkDataBase() {
    SQLiteDatabase checkDB = null;
    try {
       
checkDB = SQLiteDatabase.openDatabase(DB_FULL_PATH, null,
                SQLiteDatabase.OPEN_READONLY);
        checkDB.close();
    } catch (Exception e) {
        // database doesn't exist yet.
    }
    return checkDB != null ? true : false;
}

public void CreateTable( String CREATE_TABLE){
db.execSQL(CREATE_TABLE);
}
//String s="CREATE TABLE user (ID INTEGER PRIMARY KEY, phone NUMERIC, Name TEXT)";
public void insertDB(ContentValues values,String table) {
//db.insert(table, null, values); // it will create new rows and wont merge if already exist. i.e. insert
db.replace(table, null, values); // it will merge data in existing rows or else creates new row .i.e insert or update
}
public Cursor resultDB(String query) {
//Vector vector = new Vector();
String res="";
Cursor cur = db.rawQuery(query,new String[]{});
Rcount=cur.getCount();      
return cur;
}

public String[] getAllResultStr(String query,int pos)
    {
        Cursor cursor = db.rawQuery(query,new String[]{});

        if(cursor.getCount() >0)
        {
            String[] str = new String[cursor.getCount()];
            int i = 0;

            while (cursor.moveToNext())
            {
                 str[i] = cursor.getString(pos);
                 i++;
             }
            cursor.close();
            return str;
        }
        else
        {  cursor.close();
            return new String[] {};
        }
    }

public List getAllResultList(String query,int pos)
    {
        Cursor cursor = db.rawQuery(query,new String[]{});
        List list=new ArrayList(10);

        if(cursor.getCount() >0)
        while (cursor.moveToNext())
                list.add( cursor.getString(pos)) ;
        
        return list;

    }

public int getRowCount() {
return Rcount;
}


public void updateDB(ContentValues values,String tbname,String whereClause,String [] whereArgs) {
db.update(tbname,values, whereClause, whereArgs);
}

public void deleteDB(String TABLE_NAME,String WHERE,String[] args) {
db.delete(TABLE_NAME,WHERE,args);
}
}

Thursday, May 17, 2012

RandomFileWriter in Andriod



import java.io.File;
import java.io.RandomAccessFile;

import android.os.Environment;
import android.util.Log;

public class RandomFileWriter {
public long writeData(String text,String path,long seek){
try {
// example path : "/data/data/com.example.test/file"
RandomAccessFile file = new RandomAccessFile(path, "rw");
long i=file.length()-seek,j;
Log.i("File length",""+i);
file.seek(i);
file.writeBytes(text);
j=file.getFilePointer();
file.close();
return j;
}catch (Exception e) {
// TODO Auto-generated catch block
Log.d("RandomFileWrite.java","Exception: "+e.getMessage());
return 0;
}
 
}
public void seekWrite(String text,String path,long seek) {
try {
RandomAccessFile file = new RandomAccessFile(path, "rw");
file.seek(seek);
file.writeBytes(text);
file.close();
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d("RandomFileWrite.java seekwrite","Exception: "+e.getMessage());
}
}
String getExternalPath(){
return Environment.getExternalStorageDirectory().toString();
}

boolean isMediaReadOnly(){
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    // We can only read the media
   
  return true;
}
return false;
}
boolean isMediaMounted(){
String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    Log.i("Exter", "media found: "+Environment.getExternalStorageDirectory());
  return true;
return false;
}
public void createDir(String path,String dir){
new File(path+dir).mkdir();
}
public void createDir(File dirPath){
dirPath.mkdir();
}
public boolean deleteDir(File dir) {
    if (dir.isDirectory()) {
        String[] children = dir.list();
        for (int i=0; ilength; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }
        }
    }

    // The directory is now empty so delete it
    return dir.delete();
}
public boolean delFile(File f){
return f.delete();
 
}

void copy(File src, File dst) throws Exception{

    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;
   
    RandomAccessFile in = new RandomAccessFile(src, "r");
RandomAccessFile out = new RandomAccessFile(dst, "rw");
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
   
}

}

Friday, April 27, 2012

WAYSMS API PHP


  function sendSMS($url) {
    $userAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
    $html = curl_exec($ch);
    if (!$html) {
        echo "
CURL Page: " . $url;

        echo "
CURL Error Number: " . curl_errno($ch);

        echo "
CURL Error Desc: " . curl_error($ch);

        return FALSE;
    } else {
        return trim($html);
    }
    }
   
// Note: provider can be changed by setting $provider  to any of the provider say 'fullonsms'
    $toMobile ='Recipient number';
    $message=urlencode("hello world");
    $uid='Your mobile no';
    $password='Password';
    $provider='way2sms';


$url="http://ubaid.tk/sms/sms.aspx?uid=$uid&pwd=$password&msg=$message&phone=$toMobile&provider=$provider";
  
 if(sendSMS($url)=='1')
echo'\n Message sent...!';


/* Note:
List of Providers: way2sms, fullonsms, smsindia, whozzat, smsinside, site2sms
*/

Wednesday, January 11, 2012

FLAMES- IN JAVA APPLET

Hi all its curious to know about relationship and its fun to play with flames..
here i written code for finding the result in a single click...no need to compute in a paper to find..
Click here to Play with FLAMES.

copy the files to a directory say c:/
go to Command prompt
change directory to c:\
Type the following

cd c:\
appletviewer flames.java

Download the files given below...
Click here to download flames.java
Click here to download flames.class

or
if u want to simply view applet in a browser instead of command prompt open the following webpage.
Note:Your browser must have JRE.

Click here to see Demo

Monday, January 9, 2012

mChessPAD - Android Application for Chess Tournament

An Chess Recorder application - "m-Chess Pad" aka mobile chess pad.
No need of keeping track of score sheets. This application enables chess moves recorded electronically in a PGN Notation.




mChessPAD is Chess notation application for Android which can be used by players to record the moves in PGN format while playing instead of a score sheet. It doesn't have chess engine to play chess
Before entering to the moves, the details about the tournament like tournament name, location, round and about the player like FIDE ID, player name, ratings are to be entered. After submitting the tournament details the chess board will be displayed on screen to record the moves similar to a Chess Score Sheet.

Each player will be given with option to undo the last move. When the game ends, the UI will be displayed with option to select appropriate result. Games are stored in standard PGN format. The game data will be stored in the name of tournament. By default the game data will be stored locally on device after finishing the game. The copy of game data can be sent to SD-Card after finishing the game (optional).
Also you can export chess notations in PGN format. PGN data can be managed like copying/moving to SD card and delete the existing PGN game data from local storage. Once the game is recorded, you can save/replay the game to/from your mobile device or backup to SD Card. Filter the game based on tournament name. View particular game tournament info/summary.

Note: Please do comment for feedback or request regarding for app development..!!

Tuesday, January 3, 2012

Make use of SMS API's

Just we need to have the account in one of the following sms provider.
  1. Way2sms : 140 Chars
  2. Full On SMS : 160 Chars
  3. SMS India : 160 Chars
  4. Whozzat : 470 Chars
  5. SMS Inside : 160 Chars.
  6. Site 2 SMS : 260 Chars.
  7. SMSFI.com : 138 Chars.
WAY2SMS API:
Today I am going to explain how to use my WAY2SMS API service in your own application.
http://ubaid.tk/sms/sms.aspx?uid=” + uid + “&pwd=” + password + “&msg=” + message + “&phone=” + no + “&provider=way2sms”

Your can use cURL for PHP

C# CODE:
The Source Code example given below is in C# and can be used in any .NET Application directly.

public void send(string uid, string password, string message, string no)
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(“http://ubaid.tk/sms/sms.aspx?uid=” + uid + “&pwd=” + password + “&msg=” + message + “&phone=” + no + “&provider=way2sms”);
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
respStreamReader.Close();
myResp.Close();
}

NOTE : Don't forget to use namespaces
using System.Net;
using System.IO;



NOTE:

Required Parameters : uid, pwd, phone, msg.
uid : your userid for the required sms provider
pwd : your password for the required sms provider
provider : way2sms(default), fullonsms, smsindia, whozzat, smsinside, site2sms. if you do not specify any provider, way2sms will be used by default.
phone : phone number whom you want to send sms. seperate multiple phone numbers with a comma (,)
msg : your sms message, unlimited chars. will be sent as multiple msgs if crosses the message length for any provider
codes : 1. completely optional parameter. send this if you require a user friendly msg from the server.
for example, if codes=1 is not provided the server will return the result as an integer.
Output Flags:
1 means SMS sent,
-1 means some server error,
-2 means invalid username,
-3 means invalid message text,
-4 means login failed.
Currently, the following service providers are supported


Wednesday, November 30, 2011

Softwares

Hi all here i included necessary software tools...

Sunday, April 24, 2011

How to Make bootable Windows 7 DVD

Windows 7 Bootable


Note:
you should select and change to 4.7gb as DVD size in Ultra ISO at top right corner.

Download boot_se7en.bif below

Saturday, April 23, 2011

Remove Windows7 Activation

To make windows 7 as full version without activation using keys.
  1. Download RemoveWAT tool
  2. Click and run as Administrator.
  3. Cilck on 'Remove WAT 'option.
  4. Then Wait after explorer restarts and see your windows 7 property window does not show " 30 days to activate windows" windows area.
You can download RemoveWAT tool from here

Tuesday, April 19, 2011

MYSQL connectivity Java

// java bean for database connection to MySQL

package db;
import java.sql.*;

public class DbConnect {

private Connection conn = null;

public Connection OracleConnect() {
try {

Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
System.out.println("connected");
//return conn;
} catch (Exception e) {
//in case no password error catching error and try again.
try{
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
}
catch (Exception ee) {
System.out.println("Error in Database Connection2"+ee.getMessage());
}

System.out.println("Error in Database Connection1"+e.getMessage());
}
finally{
return (conn);
}
}

protected void CloseConnection() {
try {
conn.close();
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}



Tuesday, February 8, 2011

Random number generation in Java

import java.util.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class RandomGen {

public String genRandom() throws Exception {

String random = "";

Date date = new Date();

SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssSS");

random+=sdf.format(date);

return random;
}

}

Friday, February 4, 2011

Store and Read image from Database Using Java



/* To Store image in database- Store.java */
import java.io.*;
import java.sql.*;

public class Store {


public static void main(String args[])throws Exception


{Connection con=null;
String url="";



try{
// Step 1. Load the Type 1 database driver:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Step 2. Create a connection to the database
// using pre-defined Data Source:
File f=new java.io.File("c:/Temp.accdb");
File c=new java.io.File(System.getProperty("user.dir")+"/Temp.accdb");

if(f.exists())
url= "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" +f.getPath();
else if(c.exists())
url= "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" +c.getPath();

con = DriverManager.getConnection(url,"","");
File imgfile = new File("D:/semanticweb.jpg");

if(!imgfile.exists())
imgfile=new File("semanticweb.jpg");

FileInputStream fis = new FileInputStream(imgfile);
PreparedStatement psmnt = con.prepareStatement("INSERT INTO IMAGESTORAGE(IMAGE) VALUES(?)");
psmnt.setBinaryStream(1, (InputStream)fis, (int)(imgfile.length()));
int insertCount= psmnt.executeUpdate();
System.out.println(insertCount);
psmnt.close();
con.close();
}

catch(Exception e)
{
System.out.print(""+e);
}
}
}



/* To retrieve image from database and store in local directory- Retrieve.java */

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

public class Retreival
{


public static void main(String args[])throws Exception


{
Connection con=null;
String url="";

int c;


// Step 1. Load the Type 1 database driver:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Step 2. Create a connection to the database
// using pre-defined Data Source:
File f=new java.io.File("c:/Temp.accdb");
File ff=new java.io.File(System.getProperty("user.dir")+"/Temp.accdb");

if(f.exists())
url= "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" +f.getPath();
else if(ff.exists())
url= "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" +ff.getPath();

con = DriverManager.getConnection(url,"","");
PreparedStatement psmnt = con.prepareStatement("SELECT IMAGE FROM IMAGESTORAGE");
ResultSet rs = psmnt.executeQuery();
if(rs.next())
{

InputStream fis1;
FileOutputStream fos;
fis1 = rs.getBinaryStream("image");
fos = new FileOutputStream(new File("SunsetImageRead.jpg"));

while ((c = fis1.read()) != -1)
{
fos.write(c);
}

fis1.close();
fos.close();

}

}
}


Click here to download Complete workspace (database,image,Retrieve.java, Store.java)




Send Mail in Java


package mail;

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class SendMail {
String MAIL_SERVER = "smtp.gmail.com";


public void Sendmail(String USERNAME,String PASSWORD,String fromAddress,String toAddress,String subject,String message) {
try {

Properties properties = System.getProperties();
properties.put("mail.smtps.host", MAIL_SERVER);
properties.put("mail.smtps.auth", "true");

Session session = Session.getInstance(properties);
MimeMessage msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(fromAddress));
msg.addRecipients(Message.RecipientType.TO, toAddress);
msg.setSubject(subject);
msg.setText(message);

Transport tr = session.getTransport("smtps");
tr.connect(MAIL_SERVER, USERNAME, PASSWORD);
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
} catch (AddressException ex) {
System.out.println(ex.getMessage());
}
catch (MessagingException ex) {
System.out.println(ex.getMessage());
}

}



public static void main(String[] args){

String USERNAME="xxxx@gmail.com";
String PASSWORD="your password";
String fromAddress="xxx@gmail.com";
String toAddress="toaddress";
String subject="your subject";
String message="your message";

s.Sendmail(USERNAME, PASSWORD, fromAddress, toAddress, subject, message);

}


}



click here to download mail.jar and SendMail Java bean

Friday, December 17, 2010

DB2 connectivity code

try{
Class.forName("com.ibm.db2.jcc.DB2Driver");
System.out.println("JDBC IBM Driver is loaded");
}
catch(Exception e)
{
System.out.println("Exception 1 :"+e);
out.println("Exception 1 :"+e);
}
Connection conn=null;
Statement stmt;
try{


conn=DriverManager.getConnection("jdbc:db2://localhost:50000/TEMP" ," db2admin" ,"db2admin");
System.out.println("Connected to DB2");
//out.println("Connected to DB2");
}
catch(Exception e)
{
System.out.println("exception 2 : "+e);
//out.println("exception 2 : "+e);

}
try{
PreparedStatement stm = null;
stmt=conn.createStatement();
ResultSet r=stmt.executeQuery("select * from SYSTEM.TEM");
//out.print("DFDF:");
while(r.next())
{out.print(""+r.getString(1));
}
conn.close();
}
catch(Exception e){
}
$2.49 .COM at GoDaddy.com! Expires 5/14/13