Wednesday, May 4, 2011

Java with MySQL

Java is a popular language or may be the most popular language now. From this post I'm going to show how to connect MySQL database to java program. (this is a simple program with simple db)

1. You need to create a data base in MySQL and create a table. Then you can insert values to the table. If you are not familiar then use following lines. ( red color : not syntax )

                         mysql> CREATE DATABASE myData;
                         mysql> GRANT ALL ON myData.* TO name@localhost IDENTIFIED BY 'password';
                         mysql> use myData
                         mysql>  create table student(name varchar(30), city varchar(30));
                         mysql> insert into student values("Amy","Texas");

         
2. Now you need to download MySQL java connector. click
    for Windows download ZIP Archive and for Linux download TAR Archive

3. Extract the downloaded file and check the mysql-connector-java-5.1.16-bin.jar file is available or not.    If not then you need to check again.....

4. Open NetBeans IDE and create a new project. download NetBeans


  5. In the project window right click on the Libraries (which placed under your          created project name) and select Add Jar/Folder.


6.  After adding the Jar file it will display like this.


7. Now the rest of the coding is simple.



 line 1 : you need to import java.sql package.
 
 line 8 : defining Driver class. You can find these things in project window. (you need to expand the .jar file)

 line 10 - 12 : passing parameters to open the connection. angmar is the user name which I have created earlier and  angmar123 is the password. myData is the DB and localhost:3306 is explained at the end of this post.
 
 line 14 : This line is to prepare a statement (a Query) and it creates in statement object.

 line 16 : To execute the prepared query this line can be use.    The result is stored as result object which has been create by using ResultSet class.

 line 18 : Return a boolean type value (true or false)

 line 20 : To get the the result as a String  .getString() method can be use. 1 will gives the 1st value.
       


  •  localhost:3306 -> MySQL is using port 3306. To get that you can run following commands in CMD or Terminal.
        Windows: 
          :> netstat -ano
           you will get the pid, use task manager to get the correct application or service to that pid.

        Linux:
          # nmap -sS localhost
        you need to install nmap to execute this command.

Saturday, April 2, 2011

The Matrix has you

            Do you remember a movie called The Matrix (a science fiction-action film) which has been written and directed by Larry and Andy Wachowski in 1999? If not, then you haven’t watch this movie yet.  The reason is no one will ever forget this movie, even they don’t understand.  I’m not going to tell about that movie, I’m going to tell about the reality of the movie. The basic theme of this movie is a virtual world called matrix. Is this world can be implement in the real world? Now that sounds interesting.
       In most of the movies, we can see computing stuff like hacking, login remotely, accessing the internet, chatting via the internet and, blah blah blah....The fact is most of them are not using real systems, and they just control the system by using unknown commands and methods. Somehow in The Matrix movie, there is a scene that an infamous female hacker called Trinity is trying to login a system remotely.  Check this out.

 In this picture she uses a Linux system and NMAP (a network mapping program). Not only NMAP but also she uses SSHnuke (the real tool is SSH - Secure Shell) to login to the remote system as root (Admin). That's really cool. Still you may think is it possible to build a virtual world (which has everything like the real world) in side a computer or a server.  There are little evidences we can think of it. I’ll show them from my next post.

Wednesday, March 23, 2011

Forgetting Root

What happen if you forgot your GNU/Linux root password? 

Worry? ah.... 

Ok. I'm going to describe a method which can be helpful to you. I have tested this method in my Linux OS (debian 6.0 ). 
Here what you need to do, first of all, make sure what is the boot loader you are using. You can check it easily by reading the name when your PC boots. If your boot loader is LILO then this method is not for you. If your boot loader is GRUB .............
 Follow these easy steps. Unfortunately, I don't have any screen shot. Because of that I have used one screen shot from the internet.


  Examine the screen shot at the end of this post. 
 1. Reboot the PC and press arrow keys when the boot loader appear.

 2. Select the OS and press 'e'
 3. Select the kernel mode. 
              You can find this in the top of the list. I can give a phrase. "linux /boot/vmlinuz ". Try to find that line.
FYI :  vmlinuz is the name of the Linux kernel executable.

 4. To edit that line, press 'e' again. For Grub V1.9+, you don't need to do that.

 5. Now go to the end of the line by hitting 'End' key. Type the following path to initialization after a space.
      init=/bin/bash
 6. Now exit from the edit mode and press 'b' to boot. For Grub V1.9+ use Ctrl+x
 7. After the system boots type following in the command prompt.
                #mount -o remount, rw /
                    #passwd
           
      Enter your new password.

              #sync
                  #mount -o remount, ro /
                  #reboot

 8. Thatz it. Hopefully, this method will work for your system. However, I can't grantee.

              

Friday, February 25, 2011

Setting up LAMP server

From this post you are going to learn how to set up LAMP server on your linux operating system. I'm using GNU/Linux Debian 6.0 distro. You can directly apply these methods for DEB based Linux systems (Ubuntu). For the RPM based systems (Redhat, Fedora, Suse ...... ) you need to apply different commands.
Ex: for DEB
      #apt-get install package-name
      for RPM
      $ yum install package-name
      $ zypper install package-name

LAMP again.........

First of all you need to install few packages, you can't find a package called LAMP, LAMP is a collection of packages which belongs to PHP and MySQL.

1.you need to update your source list.
     #apt-get update
   then install apache2 and php5 or any php version which is compatible to your distro.
    #apt-get install apache2 php5 libapache2-mod-php5

2. Run a php script

<?php
        echo "Hello World\n";
?> 

save this code in to the test.php file and you should place it /var/www/. (you can give any name with php extinction)
interpret the code by using php command
# php /var/www/test.php
 

3. MySQL and phpMyAdmin
   
    To do database stuff you need to install MySQL (complete package with most of the utilities) and for the php database stuff you need to install phpMyAdmin.

    #apt-get install mysql-server mysql-client php5-mysql
    #apt-get install phpmyadmin

4. Using MySQL

    To use MySQL, you need to have a user name and password. In order to add a new user ....................

   #mysql
  you will get a prompt like this
   mysql>
   mysql> CREATE DATABASE myData
   mysql> GRANT ALL ON myData.* TO name@localhost IDENTIFIED BY 'password';
   mysql> exit
  
   test your user name
   # mysql -u name -p myData

5. Dealing with phpMyAdmin

    phpMyAdmin a web based SQL database handler. In order to use phpMyAdmin open your favorite web browser and use this URL ( if you haven't set a domain name )

    http://localhost/phpmyadmin/

    and give your user name and password there. ( which you have created for the SQL database )


6. Run php in your web browser

   We have already done with the basic LAMP configuration. Still we haven't check apache web server   (you don't need to configure apache2.conf file for the basic LAMP configuration).
        I.  Create a php script file (as I explained before ) in the /var/www/ directory.
        II. Just open a web browser again and type
             http://localhost/test.php

Note: red color - user define names (not keywords)

Thatz it. Enjoy the LAMP server.
  


Wednesday, February 16, 2011

Install tar.bz2 in linux

If you want to install an application which is not listed in your linux distro sources you need to find an installable file which suitable to your distro.
example:
                for debian/ubuntu, you need to download .deb files
                for fedora/suse/redhat you need to download .rpm files

If you can find .bin file, that would be the easiest way to install the application.
In this post I'm going to show how to install the application from the hardest way. (only use this method if you fail to find above files, and this method can be use for any linux distro)
Ok, now I'm going to install seamonkey. (a web browser based on firefox)

1. Download tar.bz2 file.

2. Make a directory and move the downloaded tar.bz2 file to that directory.

To make a directory ( "seamonkey" is the name I have used)

mkdir seamonkey

To move tar.bz2 file ( "seamonkey-2.0.11.tar.bz2" is the name of tar.bz2 )

mv seamonkey-2.0.11.tar.bz2 ./seamonkey/
cd seamonkey/
 
3. Extract .tar.bz2 file ( you can use full name without using * )

tar jxvf sea*.tar.bz2

4. Change the directory to seamonkey which has been extracted.

cd seamonkey/


5. Finally run the application by using

./seamonkey

6. Configure the application launcher ( the way is depends on the desktop environment )
for GDM


FYI: This method is for seamonkey, for the other applications, open the .tar.bz2 file then you can find the README.txt. You will find a similar method as above.

Saturday, February 12, 2011

Live HTTP headers for Firefox

From this post you are going to learn how to install Live HTTP headers tool.
What is Live HTTP headers tool?
                       It's a tool which gives all the information about the site you are visiting. That is the simplest answer by the way.
Follow these easy and dirty steps.

1. Install Live HTTP headers tool.
    You need to download firefox addons. click here
 or for direct download ( other browsers ) click here
 

2. Allow to install



3. Hit on Install Now






4. Restart Firefox by clicking Restart Firefox



5. To run Live HTTP headers tool
    tools > Live HTTP headers

 
 6. Now you can see the meta data of the site you are visiting. enjoy !!!