Sunday, February 6, 2011

Using Rapidshare.com api to check file status on rapidshare.com

/*********************************************************************************
Program to demonstrate how to that file exist on rapidshare.com server using api provided by rapidshare.com
  Developed by : Malhar Vora
  Developed on : 6-1-2011
  Development Status : Completed
  Email              : vbmade2000@gmail.com
  WebSite            : http://malhar2010.blogspot.com
**********************************************************************************/
 import java.net.*;
import java.io.*;
import java.util.*;

public class RapidChecker
{
 public static void main(String []str)
 {
  URL u=null;
  String temp[];
  Scanner sc = null;
  String strurl=null;
  try{
  
   sc = new Scanner(System.in);
   System.out.println("Enter rapidshare url to check :");
   strurl = sc.nextLine();
   u = new URL(strurl);
   
   //Getting fileid and filename by splaitting string into parts
   temp = u.getFile().split("/");
   
   //Calling function to check file status
   checkRapidShareFile(Integer.parseInt(temp[2].trim()),temp[3]);
   
  }
  catch(Exception e)
  {
   System.out.println("Error in checking file");
  }
  
 
 }
 
 static void checkRapidShareFile(int file,String filename)
 {
  URL u = null;
  InputStream is = null;   
  DataInputStream dis = null;
  String s=null,url=null;
  String data[];
   
  
  try
  {
   url = "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=checkfiles&files=" +file + "&filenames=" + filename;
   u = new URL(url);
   is = u.openStream();
   dis = new DataInputStream(is);
   
   s=dis.readLine();
   data = s.split(",");
   
   
   System.out.println(data[4]);
   
    if(data[4].equals("0"))
    {
    System.out.println("File not found");
    }
    else if(data[4].equals("1"))
    {
    System.out.println("File found");
    }
    else if(data[4].equals("3"))
    {
    System.out.println("Server down");
    }
    else if(data[4].equals("4"))
    {
    System.out.println("File is illegal");
    }
    else if(data[4].equals("5"))
    {
    System.out.println("File is locked because 10 download is already done");
    }
    else
    {
    System.out.println("Undefined response");
    }
    
    
   
  }
  catch(Exception e)
  {
   System.out.print(e);
  }
  finally
  {
   try
   {
    dis.close();
    is.close();
   }
   catch(Exception e2)
   {
     System.out.print("Error in closing streams");
   }
  }
  
 }
 
}

Saturday, February 5, 2011

Connect MS Access database using Type - I JDBC driver

import java.sql.*;

/*********************************************************************************
Program to demonstrate connection to MS Access database using JDBC driver Type - I
  Developed by : Malhar Vora
  Developed on : 6-1-2011
  Development Status : Completed
  Email              : vbmade2000@gmail.com
  WebSite            : http://malhar2010.blogspot.com
**********************************************************************************/

public class dbcon
{
public static void main(String[] args)
{


 Connection conn=null;
 Statement st=null;
 ResultSet rs=null;
 try { 
  Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
 } 
 catch (Exception E) {
  System.err.println ("Unable to load driver.");
  E.printStackTrace ();
 } 
 
 
 try { 
  String db = "jdbc:odbc:db1"; 
  conn = DriverManager.getConnection (db, "","");
  st = conn.createStatement();
  rs = st.executeQuery("Select * from emp");
  while(rs.next())
  {
    
   System.out.println(rs.getString(1));
  }
  System.out.println ("*** Connected to the database ***"); 

    
 } 
 catch (SQLException E) { 
  System.out.println ("SQLException: " + E.getMessage()); 
  System.out.println ("SQLState: " + E.getSQLState()); 
  System.out.println ("VendorError: " + E.getErrorCode()); 
 } 
 try { 
  st.close();
                if(conn!=null)
                {
                     conn.close (); 
                } 
 } 
 catch (SQLException E) {
  System.err.println ("Unable to load driver.");
  E.printStackTrace ();
 } 
}

}