Monday, 24 March 2008

MS SQL Server 2005 设置

MS SQL Server 2005

1. 设置id 号自动增加: 设计字段的时候使用, identity - yes.

2. 服务器消耗资源过大, 可以下载一个托盘小程序来管理:

介绍: http://www.sqldbatips.com/showarticle.asp?ID=46

下载: http://www.sqldbatips.com/samples/code/SQL2005SCM/SQL2005_Service_Manager.zip

3.DotNet连接数据库的方法:

The SQL Server .NET Data Provider
连接SQL Server数据库
"data source=服务器名;initial catalog=数据库名;user id=sa;password=;"

The OLE DB .NET Data Provider
连接SQL Server数据库
"Provider=SQLOLEDB;Persist Security Info=False;Data Source=服务器名;Initial Catalog=数据库名;User ID=sa;Password=;"
连接Oracle数据库
"Provider=MSDAORA;Data Source=服务器名;User ID=用户ID;Password=密码;"

连接ACCESS数据库
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=*.mdb"

Oracle客户端连接Oracle
连接Oracle 7
"Provider=MSDAORA.1;User ID=;Data Source=;Password="
连接Oracle 8
"Provider=OraOLEDB.Oracle.1;User ID=;Data Source=;Password="

DotNET Managed Provider for Oracle
连接Oracle 8
"Data Source=; User ID=; Password="
命名空间是System.Data.OracleClient

Friday, 21 December 2007

double add in Java

public class Arith {
private static final int DEF_DIV_SCALE = 10;

/**
* 两个Double数相加
*
@param v1
*
@param v2
*
@return Double
*/
public static Double add(Double v1,Double v2){
BigDecimal b1
= new BigDecimal(v1.toString());
BigDecimal b2
= new BigDecimal(v2.toString());
return b1.add(b2).doubleValue();
}

/**
* 两个Double数相减
*
@param v1
*
@param v2
*
@return Double
*/
public static Double sub(Double v1,Double v2){
BigDecimal b1
= new BigDecimal(v1.toString());
BigDecimal b2
= new BigDecimal(v2.toString());
return b1.subtract(b2).doubleValue();
}

/**
* 两个Double数相乘
*
@param v1
*
@param v2
*
@return Double
*/
public static Double mul(Double v1,Double v2){
BigDecimal b1
= new BigDecimal(v1.toString());
BigDecimal b2
= new BigDecimal(v2.toString());
return b1.multiply(b2).doubleValue();
}

/**
* 两个Double数相除
*
@param v1
*
@param v2
*
@return Double
*/
public static Double div(Double v1,Double v2){
BigDecimal b1
= new BigDecimal(v1.toString());
BigDecimal b2
= new BigDecimal(v2.toString());
return b1.divide(b2,DEF_DIV_SCALE,BigDecimal.ROUND_HALF_UP).doubleValue();
}

/**
* 两个Double数相除,并保留scale位小数
*
@param v1
*
@param v2
*
@param scale
*
@return Double
*/
public static Double div(Double v1,Double v2,int scale){
if(scale<0){
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b1
= new BigDecimal(v1.toString());
BigDecimal b2
= new BigDecimal(v2.toString());
return b1.divide(b2,scale,BigDecimal.ROUND_HALF_UP).doubleValue();
}

}

Monday, 17 December 2007

object and reference

今天在书上看到一个这样的例子

class Number {
int i;
}
public class Assignment {
public static void main(String[] args) {
Number n1 = new Number();
Number n2 = new Number();
n1.i = 9;
n2.i = 47;
System.out.println("1: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1 = n2;
System.out.println("2: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1.i = 27;
System.out.println("3: n1.i: " + n1.i +
", n2.i: " + n2.i);

}
}

我感觉最后打印出来的一行很奇怪, 为什么改变n1.i的值n2.i的值也自动变化了.
书上这样解释:

Changing the n1 object appears to change the n2 object as well! This is because both n1 and n2 contain the same reference, which is pointing to the same object. (The original reference that was in n1, that pointed to the object holding a value of 9, was overwritten during the assignment and effectively lost; its object will be cleaned up by the garbage collector.)

n1.i = n2.i 属于基本类型的传值, 不属于引用. 你改变 n1.i的值是不会影响到 n2.i的.

关于对象的引用我还是有点晕哦...

About Me

My photo
It is a nice blog, isn't it?