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.

Configuring the Eclipse Java IDE to use CPLEX libraries

Question

How do I configure the Eclipse Java IDE to use CPLEX libraries?

Cause

To specify the configuration details required to connect the Eclipse Java IDE with CPLEX libraries.

Answer

Perform the following steps to configure Eclipse with CPLEX:
1. If you are creating a new Java project
File -> New -> Java project
Else, import the existing project into your workspace
File -> Import -> Expand on 'General' -> Select 'Existing Projects into Workspace'

2. Create source (class) files as needed. To add a new class to the project,
Right click on the source folder (src) -> New -> Class, specify a name, change the
properties like package, modifiers, automatic stubs etc as required, and then click 'Finish'.
To add an existing java file to the project, simply drag and drop the .java file into the 'src'
folder of the project. Sample java programs can be found under <cplex>\examples\src\java
directory.

3. Include the CPLEX jar in the project
a) Project -> Properties -> Java Build Path -> Libraries tab ->
b) Click the 'Add External JARs ...' button and point to cplex.jar
file (found under the <CPLEX>/lib directory)

4. Run Configuration setup
a) Run -> Run Configurations ... -> Java Application
b) Right click to select 'New' if no Run Configuration exists or select the one
which you would like to configure.
c) On the 'Main' tab select your main class (the class containing
the main() function that you want to run).
d) On the 'Arguments' tab add the following to 'VM arguments' section
-Djava.library.path=<path_to_so_or_dll>
where <path_to_so_or_dll> is the directory that contains the
libcplex<version>.so (Linux) or cplex<version>.dll (Windows) file found
by default under the <CPLEX_installation_dir>/bin/<port> directory.
e) If the PATH environment variable is globally defined and includes CPLEX's
.dll or .so (platform dependant) files, then the previous step is not required.
f) This step is required only if you are using CPLEX 12.1 or an earlier version.
If CPLEX's license path is not globally defined under the ILOG_LICENSE_FILE
environment variable, then you can do so in the 'Environment' tab. Click 'New'
and enter ILOG_LICENSE_FILE as the Name and <license_file_location> as the
Value. The <license_file_location> needs to specify the license file name as well and not
just the directory it is present under.

5. You should now be able to run the program.

original link: http://www-01.ibm.com/support/docview.wss?uid=swg21449776

mercredi 2 mars 2011

use iChat to Sychronize sina twitter

申请一个gmail 打开ichat 登入ichat  账户类型选googletalk

然后在sina的微博里面在工具里面选择绑定gtalk 然后ichat 会叫你加机器人好友 然后你加就可以了 以后想发博客直接发给机器人就可以了

机器人指令说明(你可以用下面的指令让新浪微博小助手来做一些事情)
关闭 所有用户新微博提醒:/toff
开启 所有用户新微博提醒:/ton
关闭 某个用户的微博提醒:/toff 用户昵称
开启 某个用户的微博提醒:/ton 用户昵称
关闭 新评论提醒:/poff
开启 新评论提醒:/pon
关闭 新私信提醒:/moff
开启 新私信提醒:/mon
关闭 新粉丝提醒:/foff
开启 新粉丝提醒:/fon
关闭以上所有消息接收:/off
开启以上所有消息接收:/on
发私信:/d 粉丝昵称 私信内容(例如给张三发私信:/d 张三 你吃饭不?)
忘记了以上指令?没关系,直接发送:/help