Pages

Wednesday, December 26, 2012

Connect Java Applications to Mysql Database in Ubuntu Using Netbeans IDE

Ubuntu Terminal

  1. Install Mysql Server and Mysql Client from Ubuntu Software Center
  2. Install JDBC Connector by typing in the terminal
    sudo apt-get install libmysql-java
  3. Check if can connect to mysql by typing
    mysql -u root -p
  4. Create required database and tables. For ex: create a database called newyear and table called party with fields id and name

Netbeans IDE

  1. Create a Java project/application in Netbeans
  2. In the main .java file add lines similar to this and save
    
    package javaapplication6;
    import java.sql.*;
    
    public class JavaApplication6 {
        
        private static final String url = "jdbc:mysql://localhost/newyear";
        private static final String user = "root";
        private static final String password = "";
            
        public static void main(String[] args) {
            System.out.println("Hello world!!");
            Statement stmt = null;
            try {
                    Connection con = DriverManager.getConnection(url, user, password);
                    System.out.println("Success");
                    stmt = con.createStatement();
                    String sql = "INSERT INTO party " + "VALUES (1, 'joe')";
                    stmt.executeUpdate(sql);
    
            } catch (Exception e) {
                    e.printStackTrace();
            }        
            
        }
    }
    
  3. Then right click on the project/application in the project explorer and click on Properties
  4. In the project properties window, select libraries tab. Then click on Add Jar/Folder button
  5. Select mysql.jar from /usr/share/java directory and then click on Ok
  6. Now save and run the project/application and check for output in the panel

Ubuntu Terminal

  1. To check if the record is inserted, type:
    mysql -u root -p
    show databases;
    use newyear;
    show tables;
    select * from party;
    

Note: Just hit an enter if no password is to be set when prompted.

Install Oracle Java in Ubuntu

These steps are for installing java on a 32 bit ubuntu/linux OS.
  1. Download jdk-7u10-linux-i586.tar.gz from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
  2. Download jre-7u10-linux-i586.tar.gz from http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html
  3. The downloaded files may be stored in /home/"your_user_name"/Downloads directory
  4. Remove any oracle jdk/jre binaries if any already installed
    sudo apt-get purge openjdk-\*
  5. Create directory to hold Oracle Java JDK and JRE binaries
    sudo mkdir -p /usr/local/java
  6. Go to the directory where the downloaded files are stored
    cd /home/"your_user_name"/Downloads
  7. Copy the downloaded files into /usr/local/java and go into the directory and change the permissions
    sudo -s cp -r jdk-7u10-linux-i586.tar.gz /usr/local/java
    sudo -s cp -r jre-7u10-linux-i586.tar.gz /usr/local/java
    cd /usr/local/java
    sudo -s chmod a+x jdk-7u10-linux-i586.tar.gz
    sudo -s chmod a+x jre-7u10-linux-i586.tar.gz
    
  8. Extract the compressed binaries
    sudo -s tar xvzf jdk-7u10-linux-i586.tar.gz
    sudo -s tar xvzf jre-7u10-linux-i586.tar.gz
    
  9. Now the listing of the extracted files can be viewed by:
    ls -a
  10. Edit the system PATH file /etc/profile and add the following system variables to the system path
    sudo gedit /etc/profile
  11. Add the following lines to the end of /etc/profile file
    
    JAVA_HOME=/usr/local/java/jdk1.7.0_10
    PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
    JRE_HOME=/usr/local/java/jre1.7.0_10
    PATH=$PATH:$HOME/bin:$JRE_HOME/bin
    export JAVA_HOME
    export JRE_HOME
    export PATH
    
    
  12. Save the /etc/profile file and exit
  13. Inform your Ubuntu Linux system where your Oracle Java JDK/JRE is located. This will tell the system that the new Oracle Java version is available for use.
    sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.7.0_10/bin/java" 1
    sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_10/bin/javac" 1 
    sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jre1.7.0_10/bin/javaws" 1 
    
  14. Inform your Ubuntu Linux system that Oracle Java JDK/JRE must be the default Java.
    sudo update-alternatives --set java /usr/local/java/jre1.7.0_10/bin/java
    sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_10/bin/javac 
    sudo update-alternatives --set javaws /usr/local/java/jre1.7.0_10/bin/javaws 
    
  15. Reload your system wide PATH /etc/profile by typing the following command:
    . /etc/profile
  16. Note your system-wide PATH /etc/profile file will reload after reboot of your Ubuntu Linux system
  17. Test to see if Oracle Java was installed correctly on your system. Run the following commands and note the version of Java:
    java -version
    javac -version
    

Tuesday, December 25, 2012

ERROR 1044 (42000): Access denied for user ' '@'localhost' to database 'test'

This error may arise when running mysql from ubuntu terminal. To fix this, type:
mysql -u root -p
in the bash instead of mysql terminal.

Friday, December 21, 2012

Delete temp files in windows


  1. Click on Start
  2. Go to run
  3. Type %temp% in the open field and click on Ok
  4. Delete all the files and folders inside the Temp directory

Run PHP file from windows command line

  1. Install WAMP in D drive
  2. In the D://wamp/www folder create a file called test.php and enter the following and save:
    
    <!--php
    echo 'Yipee! Welcome to PHP';
    ?-->
    
  3. Open the cmd (command prompt) in windows and change the directory path to: D:\wamp\bin\php\php5.4.3>
  4. Now type
    php d:\wamp\www\test.php

Thursday, December 20, 2012

Complile C program in Ubuntu


  1. In the terminal, type:
    
    sudo apt-get install build-essential
    
    
  2. Create a main directory called cprog and a sub directory called helloworld to hold the C programs
    
    mkdir -p cprog/helloworld
    
    
  3. Go into that directory
    
    cd cprog/helloworld
    
    
  4. Open a file called main.c in gedit editor
    
    gedit main.c
    
    
  5. Type the following in main.c
    
    #include
    #include
    int main()
    {
    printf("\nHello World,\nWelcome to my first C program in Ubuntu Linux\n\n");
    return(0);
    }
    
    
  6. Save and exit
  7. To compile the program, go into the respective directory, as described in step3
  8. Then type:
    
    gcc -Wall -W -Werror main.c -o helloworldC
    
  9. To execute type:
    
    ./helloworldC
    

Wednesday, December 19, 2012

Install software in ubuntu using .deb file

To install software in ubuntu using .deb file, double click on it so that it links to the ubuntu software center and installs from there.

Tuesday, December 18, 2012

Display date time in php based on country


date_default_timezone_set('Australia/Melbourne');
$date = date('m/d/Y h:i:s a', time());
echo $date;

Thursday, December 13, 2012

CKEditor custom toolbar

In the ckeditor/config.js write the following

CKEDITOR.editorConfig = function( config )
{
 config.toolbar = 'MyToolbar';
 
 config.toolbar_MyToolbar =
 [
  { name: 'document', items : [ 'NewPage','Preview' ] },
  { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
  { name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','Scayt' ] },
  { name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'
                 ,'Iframe' ] },
                '/',
  { name: 'styles', items : [ 'Styles','Format' ] },
  { name: 'basicstyles', items : [ 'Bold','Italic','Strike','-','RemoveFormat' ] },
  { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote' ] },
  { name: 'links', items : [ 'Link','Unlink','Anchor' ] },
  { name: 'tools', items : [ 'Maximize','-','About' ] }
 ];
};

Monday, December 10, 2012

Execute PHP5 script from command line in ubuntu

  1. To execute a PHP script from the command line in Ubuntu you must have php5-cli installed.
  2. sudo apt-get install php5-cli
  3. After cli is installed, go to the folder where the script resides. For ex: 
  4. cd /var/www/test
    php5 index.php
    

Thursday, December 6, 2012

Set netbeans as default editor in ubuntu

  1. Install ubuntu tweak
    
    sudo apt-add-repository ppa:tualatrix/ppa
    sudo apt-get update
    sudo apt-get install ubuntu-tweak
    
    
  2. Find the MIME description for your file extension
    1. Right click on the file and click on properties
    2. In the properties window, note the text shown after Type:
    3. This is the mime description we are looking for. for ex: PHP script
  3. Add a custom program to open your filetype
    1. Start Ubuntu Tweak from the Dash, and click on the Admins tab on top; then click on the File Type Manager entry on the bottom:
    2. After the File Type Manager opens, click on All in the left sidebar, and uncheck the Only show filetypes... box at the bottom:
    3. Select any filetype on the right side, and begin typing the first few letters of the MIME description from Step 2 to automatically search and select your filetype:
    4. Double-click on your filetype, which is now selected, to edit its associated commands.
      1. Click on Add, and in the Add Application window, expand the Custom Command option on the bottom
      2. Type the command/program you want or use the Browse button to navigate to it and select it; here I have selected the Netbeans editor from my /opt folder:
        
        /opt/netbeans-7.2.1/bin/netbeans
        
        
      3. Click on Add, so the new command is now the default, and then click Close:
  4. Now right click on file and click on properties. Click on 'open with' tab. The default application should be netbeans. Close this window and open the file. It should open in Netbeans

Friday, November 23, 2012

PHP curl installation in ubuntu

While installing magento in ubuntu there may be some errors related to php curl not being installed. To work around this, try the command:

sudo apt-get install php5-curl

Wednesday, November 21, 2012

Installing phpmyadmin in ubuntu

  1. Open your terminal and type the command:
    sudo apt-get install phpmyadmin
  2. It will ask for your password, type your ubuntu password and press enter key, it will ask for confirmation. Type
    y
    and press enter key
  3. During the installation you will be prompted for a web server configuration. Select
    Apache
    and press Enter
  4. Now you will be prompted for phpmyadmin configuration, select
    no
  5. In terminal run the command:
    sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf.d
  6. Restart your apache server:
    sudo /etc/init.d/apache2 restart
  7. Open your browser and type
    http://localhost/phpmyadmin/
  8. Enter root for username and leave password field empty and click on Go
  9. You will get the following error:
    Login without a password is forbidden by configuration (see AllowNoPassword)
    when trying to login to your passwordless account; 
  10. To enable AllowNoPassword, uncomment or add the following line in /etc/phpmyadmin/config.inc.php :
    $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;
  11. To make this file editable in ubuntu, type in the terminal:
    cd /etc/phpmyadmin
    then press enter
  12. Then type
    gksu nautilus
  13. Make necessary changes and save the file. Now type
    http://localhost/phpmyadmin/
    in the browser and enter only the username as root and click on Go.

Monday, November 12, 2012

Reset password in ubuntu

  1. Reboot into recovery mode 
  2. Select Drop to root shell prompt option
  3. In recent versions of Ubuntu, the filesystem is mounted as read-only, so you need to enter the follow command to get it to remount as read-write, which will allow you to make changes:  mount -rw -o remount /
  4. If you have forgotten your username as well, type:  ls /home
  5. To reset the password, type:  passwd username  ex: passwd meenu
  6. You'll then be prompted for a new password. When you type the password you will get no visual response acknowledging your typing. Your password is still being accepted. Just type the password and hit Enter when you're done. You'll be prompted to retype the password. Do so and hit Enter again.
    Now the password should be reset. Type: exit to return to the recovery menu.
     

Thursday, November 1, 2012

grub rescue problem

  • Download boot repair software from http://sourceforge.net/p/boot-repair/home/Home/
  • Download iso version of the software(boot-repair-disk.iso) and create a bootable usb using linux live usb creator
  • Change the boot option to usb flash drive in the computer which has grub rescue problem by hitting F2 key(this is the case in lenovo laptop)
  • Then insert the created bootable usb into the computer and reboot
  • The boot repair software runs ... now choose the appropriate system version(32bit or 64bit)
  • Then choose recommended repair and follow on screen directions
  • Do a final reboot and you can see the OS loading without any grub rescue errors

Create bootable usb

To create a bootable usb from a windows 7 computer, install linux live usb creator from http://www.linuxliveusb.com/en/download
Then choose the required iso image to be extracted into the destination usb.

Friday, October 19, 2012

Posting code within editor


Integrate ckeditor with php pages

  1. Download the ckeditor.zip file
  2. Paste ckeditor.zip file on root directory of the site or you can paste it where the files are
  3. Extract the ckeditor.zip file
  4. Open the desired php page you want to integrate with ex: page1.php
  5. Add some javascript first below, this is to call elements of ckeditor and styling and css without this you will only a blank textarea
  6. 
    
    <script type="text/javascript" src="ckeditor/ckeditor.js"></script>
    
    
    
  7. Now, you need to call the work code of ckeditor on your page page1.php below is how you call it
  8. 
    
    <!--php
    // Make sure you are using a correct path here.
    include_once 'ckeditor/ckeditor.php';
    $ckeditor = new CKEditor();
    $ckeditor--->basePath = '/ckeditor/';
    $ckeditor->config['filebrowserBrowseUrl'] = '/ckfinder/ckfinder.html';
    $ckeditor->config['filebrowserImageBrowseUrl'] = '/ckfinder/ckfinder.html?type=Images';
    $ckeditor->config['filebrowserFlashBrowseUrl'] = '/ckfinder/ckfinder.html?type=Flash';
    $ckeditor->config['filebrowserUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
    $ckeditor->config['filebrowserImageUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
    $ckeditor->config['filebrowserFlashUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
    $ckeditor->editor('CKEditor1');
    ?>
    
    
    
  9. What ever name you want, you can name to it ckeditor by changing the step 6 code last line
  10. 
    
    $ckeditor->editor('mycustomname');
    
    
    
  11. Open-up the page1.php, see it, use it, share it and Enjoy

Thursday, October 18, 2012

.htaccess file redirect

// this file must exist in the current server
RewriteCond %{REQUEST_URI} etab$ [NC]

// this file or path can be in a different server
RewriteRule (.*) AM335x_eTAB.php [NC,L]

Tuesday, October 9, 2012

Image path setting in php for file upload

  • Example: $path = realpath(dirname(__FILE__)).'/uploads/products/';
  • To find server root: $_SERVER['SERVER_NAME'];
  • To find server base path to current file directory: $path = $_SERVER['SERVER_NAME'].dirname($_SERVER['REQUEST_URI']);

Friday, September 21, 2012

Lenovo Laptop Screen Does Not Display

Remove battery, unplug power, hold power button for 60 seconds, turn on computer with power plug only, then shutdown, add battery and restart.

Monday, September 3, 2012

Disable autohide launcher in ubuntu 11.04

  • On home tab, type compiz and click on CompizConfig Settings Manager.
  • Under the category list on the left side, select Desktop and then on Ubuntu Unity Plugin on the right side.
  • Set Hide Launcher to Never.

Tuesday, August 28, 2012

Restart apache

sudo /etc/init.d/apache2 restart

Change folder permissions in ubuntu

sudo chmod -R 777 folder_name

Monday, August 27, 2012

Wednesday, August 8, 2012

Drupal Custom Theme Not Detected

Generally this problem arises when the .info file is not correctly configured. Check the contents of the file and the extension of the file. It should be theme_name.info and not theme_name.info.txt or any other file extension.

Monday, June 18, 2012

Manual fix for broken image links via wysiwyg in drupal 6

While working on localhost, the path for wysiwyg images could be /sites/site_name/sites/default/files/img.jpg. But after uploading on to server, the image path could become /sites/all/default/files/img.jpg. To fix this path error manually, run the following query in the phpmyadmin sql.
UPDATE boxes SET body = replace( body, "/sites/site_name", "" )

Friday, June 8, 2012

Add external css stylesheet in drupal 6



<!--php
$inc_path = drupal_get_path('theme', 'your_theme_name') . '/path/name.css';
$file = realpath(".") ."/". $inc_path;
if(file_exists($file)) {
drupal_add_css($inc_path , 'theme', 'all', FALSE);
$vars['css']['all']['theme'][$inc_path] = 1; // this is what makes it work!
$vars['styles'] = drupal_get_css();
}
?-->


Wednesday, May 9, 2012

Configure wamp on windows7

One of the problems encountered during wamp installation on a windows 7 system is the following error:
"you don't have permission to access /phpmyadmin/ on this server"
This error can be rectified by changing the file content in c:\wamp\alias\phpmyadmin.conf

Before:
<Directory "c:/wamp/apps/phpmyadmin3.4.5/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Directory>

After:
<Directory "c:/wamp/apps/phpmyadmin3.4.5/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order Deny,Allow
        Allow from all
</Directory>

Saturday, May 5, 2012

Remove extra spaces in dreamweaver

  • While the document is open in Dreamweaver, press CTRL+F. Do the search on the source code view.
  • Check the box “Use regular expression” and uncheck any other boxes.
  • Find: [\r\n]{2,}
  • Replace: \n
  • Click “replace all”  

Tuesday, March 6, 2012

Using GET Method in php

Example Code:
HTML:
<a href="?delete=id">Delete</a>

PHP:

if(isset($_GET['delete']))
{
$result = mysql_query('DELETE FROM my_table WHERE id = '.(int)$_GET['delete']);
}