lundi 21 mars 2011

how to install mysql on ubuntu system

=======================
INSTALL AND START MYSQL SERVER

1 st step is to install the MySQL Server, it is easy to perform on Ubuntu:

    sudo apt-get install mysql-server

2: start the service:

    sudo /etc/init.d/mysql start

3: login:

    mysql -u root -p
 
    and then, enter your password.
==========================
TO USE MYSQL SERVER WITH JAVA

you have to download lib file called connector:
you can find more versions here.

when you compile the Java program, you have to include this connector file in the classpath variable;

If you use eclipse, you can include this file by selecting the project->properties->Java Build Path->Libraries->Add External Library.
==========================
SOME USEFUL SQL COMMANDS

check all available databases:

    mysql>show databases;

use a database:

    mysql>use database_name;

check all tables in this database:

  mysql>show tables;
 
delet a table in a database:

   mysql>drop table table_name;

a
==========================

mercredi 16 mars 2011

[转] java 追加内容到文件末尾的几种常用方法

import java.io.BufferedWriter;  
import java.io.FileOutputStream;  
import java.io.FileWriter;  
import java.io.IOException;  
import java.io.OutputStreamWriter;  
import java.io.RandomAccessFile;  

public class WriteStreamAppend {
      /**
       * 追加文件:使用FileOutputStream,在构造FileOutputStream时,把第二个参数设为true
       *
       * @param fileName
       * @param content
       */
public static void method1(String file, String conent) {  
    BufferedWriter out = null;  
    try {  
         out = new BufferedWriter(new OutputStreamWriter(  
                  new FileOutputStream(file, true)));  
                 out.write(conent);  
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            try {  
                out.close();  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
    }  

    /**
     * 追加文件:使用FileWriter
     *  
     * @param fileName
     * @param content
     */
    public static void method2(String fileName, String content) {  
        try {  
            // 打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件
            FileWriter writer = new FileWriter(fileName, true);  
            writer.write(content);  
            writer.close();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  

    /**
     * 追加文件:使用RandomAccessFile
     *  
     * @param fileName
     *            文件名
     * @param content
     *            追加的内容
     */
    public static void method3(String fileName, String content) {  
        try {  
            // 打开一个随机访问文件流,按读写方式
            RandomAccessFile randomFile = new RandomAccessFile(fileName, "rw");  
            // 文件长度,字节数
            long fileLength = randomFile.length();  
            // 将写文件指针移到文件尾。
            randomFile.seek(fileLength);  
            randomFile.writeBytes(content);  
            randomFile.close();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  

    public static void main(String[] args) {  
        System.out.println("start");  
        method1("c:/test.txt", "追加到文件的末尾");  
        System.out.println("end");  
    } 

原文地址:http://blog.csdn.net/jsjwk/archive/2009/02/27/3942167.aspx

mardi 15 mars 2011

how to format a double value.

public static double formatDoubleNumber (double a){
        a = Math.round(a * Math.pow(10,2));         
        a = a/Math.pow(10,2); 
        return a;       
}

lundi 14 mars 2011

Ubuntu 10.10 安装java(转)

和大多数Linux一样,一般默认安装的Open JDK,如果你只是个上网本,看看电影娱乐啥的,那肯定不用劳神了,不过如果要用JAVA来开发,还是老老实实的安装Sun JDK。还好的是,在Ubuntu 9.04以后,Sun JDK 安装已经越来越简单了。

1. 编辑 /etc/apt/sources.list

添加deb http://archive.canonical.com/ubuntu maverick partner

2. 安装JDK 


Console代码
  1. sudo apt-get update   
  2. sudo apt-get install sun-java6-jdk   

3. 可以在 /etc/jvm 查看默认的 JVM 

4. 添加环境变量

在 /etc/enviroment 中添加环境变量 :


Console代码
  1. PATH="/usr/lib/jvm/java-6-sun/bin:$PATH"  
  2. CLASSPATH="/usr/lib/jvm/java-6-sun/lib"  
  3. JAVA_HOME="/usr/lib/jvm/java-6-sun"  

顺便提一下Ubuntu10.10 里面的环境配置文件

(1)/etc/enviroment 是系统的环境变量。
(2)/etc/profile: 是所有用户的环境变量。当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置。
(3)/etc/bashrc: 为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取。
(4)~/.bash_profile: 每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件。
(5)~/.bashrc: 该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取。
(6) ~/.bash_logout:当每次退出系统(退出bash shell)时,执行该文件. 另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承 /etc/profile中的变量,他们是"父子"关系。
(7)~/.bash_profile 是交互式、login 方式进入 bash 运行的~/.bashrc 是交互式 non-login 方式进入 bash 运行的通常二者设置大致相同,所以通常前者会调用后者。

original link: http://hi.baidu.com/insidi/blog/item/090be9d182211a289a502769.html

resolution problem by using Ubuntu in virtualbox

I am using a macbook pro, where I installed a virtualbox in order to use some virtual machines.

when a Ubuntu machine is installed, the maximum resolution of the screen is 800*600, which is not enough for a big screen.

so, to solve this problem, you need only to install

virtualbox-ose-guest-x11

by using either apt-get install or Synaptic Package Manager.

how to force clear the trash can in Mac OS

open your temial and enter the trash can directory:

cd ~/.Trash/

Then, you can review all items by using ls command.

To delete all the files and folders, using the following command:

sudo rm -rf *

how to install cplex on unix-based machine

========================
first of all, you have to get
    - the distribution cplex122.x86linux.tar.gz and
    - an authentication file: access_122.ilm.

then, extract the cplex122.x86linux.tar.gz to any path you wish on your computer's disk.

next, set up an environment variable: ILOG_LICENSE_FILE which point to the access_122.ilm file.

up to now, the compiler is installed, you will have the following file structure:

    - <cplex_installed_path>
        - concert27
        - cplex122

to verify the installation:
    - go to <cplex_installed_path>/cplex122/bin/x86_darwin8_gcc4.0/ in the terminal;
    - run ./cplex to start the interactive optimizer.

if you can see the following screen, it means the cplex is well installed:

ILOG CPLEX 11.210, licensed to "inria-grenoble", options: e m b q use=10 MaintenanceEnd=20110330

Welcome to CPLEX Interactive Optimizer 11.2.1
  with Simplex, Mixed Integer & Barrier Optimizers
Copyright (c) ILOG 1997-2008
CPLEX is a registered trademark of ILOG

Type 'help' for a list of available commands.
Type 'help' followed by a command name for more
information on commands.

CPLEX>


===================

how to use cplex with Java

to compile a Java program which calls the cplex:

  javac -classpath /Users/cwang/Documents/workspace/cplex/cplex112.x86_mac/cplex112/lib/cplex.jar:.(pay attention to include the current directory by using :.)

and to execute:

  java -Djava.library.path=/Users/cwang/Documents/workspace/cplex/cplex112.x86_mac/cplex112/bin/x86_darwin8_gcc4.0/libcplex112.so -classpath /Users/cwang/Documents/workspace/cplex/cplex112.x86_mac/cplex112/lib/cplex.jar:. Diet

where the Diet is the name of the program.