Friday, December 28

Remove write protection on pen drive

Hi All,

I got the code from net :)

Here is how you can remove or uninstall write protection on pen drive. This is a common problem faced by most users. 
Often an error occurs while copying, deleting or modifying data or files for the USB. This happens because it is 'Write-Protected'. Here is a solution to the problem of the USB being write-protected. Follow the steps mentioned in this article to enable the modification, copying or deleting of files from the USB thereafter. 

Issue

This a very common problem when using USB flash drives. Sometimes when you try to copy or delete files you get an error message "Remove the write-protection or use another disk". Furthermore, it won't allow you to format it! 




Solution

To remove write protection:
  • Open Start Menu >> Run, type regedit and press Enter. This will open the registry editor.
  • Navigate to the following path:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies
  • Double click the key WriteProtect in the right pane and set the value to 0
  • In the Data Value Box, press OK
  • Exit Registry, restart your computer and then re-connect your USB pen drive to your computer.



That is it, done. Good luck!

Wednesday, December 19

BubbleSort program in Java


Hi All,


package Sorting;

/**
 *
 * @author SKiTECH
 */
public class bubbleSort {

    public static void main(String arg[]) {
        int a[] = {100, 30, 80, 20, 2, 90, 50, 11, 99, 99};
        int temp = 0;
        System.out.println("Ascending sort program");
        for (int i = a.length - 1; i >= 0; i--) {
            for (int j = 0; j < i; j++) {               
                if (a[j] < a[j + 1]) 

                {   // if you want descending order  change ">" symbol instead of  "<" (a[j] > a[j + 1])
                    temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
            System.out.println(a[i]);
        }
    }
}



OUTPUT:

~~~~~~~~

Ascending sort program                  
2
11
20
30
50
80
90
99
99
100



Descending sort program
100
99
99
90
80
50
30
20
11
2

How to Enable USB Port in Windows(if it is blocked).

Hi All,

How to Enable USB Port in Windows(if it is blocked).
Follow the steps to open a USB port in Windows machine.

1. Click Start Button, and then click Run. 

2. In the Open box, type regedit, and then click OK. 


3. and then click the following registry key: for finding the location of  USB port.

HKEY_LOCAL_MACHINE -> SYSTEM->CurrentControlSet->Services->UsbStor 

4. In the right pane, double-click "Start" option. 


5. In the Value data box, type "4" (without quotes), click Hexadecimal (if it is not already selected),  and then click OK. Note :- if 4 is entered it will open the port


6. Quit Registry Editor.



Friday, November 9

Thursday, November 8

Open Notepad Application using JAVA

/*
* Open Notepad Application using Java
*/


import java.io.File;

public class pdf {

    public static void main(String[] args) {

      try {
            Process p = Runtime.getRuntime().exec("notepad"); //Process starts notepad

            p.waitFor();
           
        System.out.println("Done");

        } catch (Exception ex) {
        ex.printStackTrace();
      }

    }
}

output:
~~~~~~~

Done


Note: it will open a notepad after the execution

Open a PDF file using JAVA

/*
* Open a PDF file in new window using JAVA
*/

import java.awt.Desktop;
import java.io.File;

public class OpenPDF {
    public static void main(String[] args) {
      try {
        File pdfFile = new File("c:\\sample.pdf"); //give your PDF location
        if (pdfFile.exists()) {

            if (Desktop.isDesktopSupported()) {
                Desktop.getDesktop().open(pdfFile);
            } else {
                System.out.println("Awt Desktop is not supported");
            }

        } else {
            System.out.println("File is not exists!");
        }

        System.out.println("Done");

      } catch (Exception ex) {
        ex.printStackTrace();
      }

    }
}

Output
~~~~~~
Done

Note: it open a PDF file in separate window

Wednesday, November 7

Oracle Database connection using Java



/**
 *  Program for simple database connectivity and records fetching from table 
 */

import java.sql.*;

public class dbCon {
    public static void main(String arg[]) throws SQLException{
        Connection con=null;
        Statement stmt=null;
        ResultSet rs=null;
        String name="";
            try{ 
                
                /*
                 * Java jdbc driver name -> oracle.jdbc.driver.OracleDriver
                 * Java url driver type  -> jdbc:oracle:thin:
                 * Address               -> @localhost "or" 120.15.87.153
                 * Port using Oracle     -> 1521
                 * Database Name         -> hbsp54db
                 * Username of Oracle    -> tp2
                 * Password of Oracle    -> tp2
                 */
                
                // Load the JDBC driver       
                Class.forName("oracle.jdbc.driver.OracleDriver");
                //Create a connection to the database
                con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:hbsp54db","tp2","tp2");
            }
            catch(Exception e){
                System.out.println("Unable to connect Database "+e);
            }
            
            String query = "Select username FROM users";     // use your table here       
            stmt = con.createStatement(); //Statment creation
            rs = stmt.executeQuery(query);  // resultset for executeQuery
            while(rs.next()){   //checking value in next record from database
              name= rs.getString(1); //geting username from user table
              System.out.println(name);
            }
            con.close();
                
}
}
 
output:
~~~~~~~

balamurgan
krishna
sri

PDF file generation code using java

// This code help to create a PDF file using java. that is stored in given file location.

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;

import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class pdfGeneration {

    public static void main(String[] args) {
        try {
            OutputStream file = new FileOutputStream(new File("C:\\newPDF.pdf")); //Saved file path

            Document document = new Document();
            PdfWriter.getInstance(document, file);

            document.open();
            document.add(new Paragraph("Welcome to TECHIE SNACKS, Author Balamurugan.M.R"));
            document.add(new Paragraph("This is simple pdf generation code \n Created on \t"+ new Date().toString()));

            document.close();
            file.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Notes: Please and Must include the " iText-2.1.5" jar file then only it works. 

You will find the jar in given location " http://grepcode.com/snapshot/repo1.maven.org/maven2/com.lowagie/itext/2.1.5 ".

Enjoy the life :)

Reading CSV file using java

// This is code  read csv file columns and display as it is in console. this is not consider empty value

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.StringTokenizer;

public class csvRead {
        public static void main(String[] args) {            
                try
                {
                        String filePath = "C:/xls/csv_person.csv";   //csv file path
                        String str = "";
                        StringTokenizer st = null;
                        int lineNo = 0, tokenNo = 0;
                     
                        //create BufferedReader to read csv file
                        BufferedReader br = new BufferedReader( new FileReader(filePath));

                        //read comma separated file line by line
                             while( ( str =br.readLine()) != null) {                            
                                br.readLine();
                              
                               //break comma separated line using ","
                                st = new StringTokenizer(str, ",");
                                while(st.hasMoreTokens()) {
                                        tokenNo++;
                                        System.out.println( st.nextToken());
                                }
                              
                                //reset token number & increment the lineNo
                                 lineNo++;
                                tokenNo = 0;
                        }
                }
                catch(Exception e){
                        System.out.println("Exception while reading csv file: " + e);               
                }
        }
}

output:
~~~~~


USERNAME
CUSTOM1
CUSTOM2
CUSTOM3
TYPE
CREATED_ON
ALLOW_NONBUDDIES
CUSTOM5
String lenght46
20501427
vivek
hello
hai
2
01-jan-12
50
record
String lenght32
40021456
vivek
sample
record
String lenght0
String lenght0
String lenght0
String lenght46
20501427
vivek
hello
hai
2
01-jan-12
50
record
String lenght0
String lenght0
String lenght0
String lenght20
basker 65
vivek

Tuesday, November 6

#1045 - Access denied for user 'root'@'localhost' (using password: NO)

Hi All,

I have the error(#1045 - Access denied for user 'root'@'localhost' (using password: NO) )

I have read solution on other post that is as follow:-
I'm just to confirm you that it's the solution.

I was writing ( UPDATE mysql ) : so please follow the next steps if you want to resolve your problem with ( #1045 - Access denied for user 'root'@'localhost' (using password: NO):

1 : go to your WAMP icon on your PC desktop screen and LEFT CLICK to open the menu, you will see MYSQL folder, CLICK to see MYSQL CONSOLE, open it.

2: now you have DOS screen ( a black screen ) :

A: if you already set a password, type it
B: if you did not do this step yet, write the following red text
B1: use mysql; and click ENTER on your keyboard
3: now write the following red text and click ENTER :

UPDATE mysql.user SET Password=PASSWORD("YOUR PASSWORD") WHERE User="root";

 your command will execute when you write this sign ( ; ) at the end of your text and click ENTER.

NOTE: replace the password "YOUR PASSWORD" by your password.

4: now write the following red text and click ENTER :

FLUSH PRIVILEGES;

5: and to exit the black DOS screen now, write exit and click enter.

------------------------- we are finished from MySQL now --------------

6: go to WAMP folder ( open your My Computer, click on C driver, and you will see WAMP folder ), click on APPS folder, and than click on your PHPMYADMIN folder ( e.g C:\wamp\apps\phpmyadmin3.5.1) and find the config.inc.php

7: open config.inc.php and find the following orange text:

$cfg['Servers'][$i]['password'] = '';  // MySQL password  (only needed and add your password now that you used in step number 3 like that).

Example:
$cfg['Servers'][$i]['password'] = 'root';

[COLOR="rgb(255, 140, 0)"]$cfg['Servers'][$i]['password'] = 'YOUR PASSWORD; // MySQL password (only needed[/COLOR]

8: now save this modification, and close config.inc.php

9: go to your web browser and type the following link :

http://localhost/phpmyadmin/

and enjoy, this is what happened with me.

Wednesday, October 17

Read Excel Sheet using JAVA

 
This is a code using for read excel sheet data as it is in java, also it display in Java console.
Before you use this code you need download and insert to this program.
Please use this URL for free download : http://poi.apache.org/download.html

Thursday, September 13

Hi All,
 

Welcome to the TECHIE SNACKS world.
 

The main theme of this blog is sharing the Knowledge in various domains and platforms of programming languages.
I hope this blog gives you the best solution to your problem (Issue).
Me and my friends share their knowledge and new idea's here for up-comers.
The viewer of this blog, Please share your idea's and stuff here. Then only we will create a new path for technology.

Once again thanks all :)





Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...