Oracle导入导出数据

导出数据:

1 将数据库TEST完全导出,用户名system 密码manager 导出到D:\conjs.dmp中
exp system/manager@orcl file=d:\conjs.dmp full=y
2 将数据库中system用户与sys用户的表导出
exp system/manager@orcl file=d:\conjs.dmp owner=(system,sys)
3 将数据库中的表table1 、table2导出
exp system/manager@orcl file=d:\conjs.dmp tables=(table1,table2)
4 将数据库中的表table1中的字段filed1以”00″打头的数据导出
exp system/manager@orcl file=d:\conjs.dmp tables=(table1) query=\” where filed1 like ’00%’\”

导入数据:

1 将D:\conjs.dmp 中的数据导入 orcl数据库中。
imp system/manager@orcl file=d:\conjs.dmp
上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。
在后面加上 ignore=y 就可以了。
2 将d:\conjs.dmp中的表table1 导入
imp system/manager@orcl file=d:\conjs.dmp tables=(table1)

2012年1月7日 | 归档于 oracle

Java Collections性能比较

本文转自IKOO大哥博客
其实这是转贴,原文地址。有时间再简单翻译下。

List – this is an ordered list of objects, insertion order is maintained and retrieval order is in the list order but items can also be random accessed, duplicate items are allowed, generally allow storage of null values (the ones below do), generally fast to iterate and find items by position but slow to do lookups

ArrayList – Unsychronized, nulls allowed (fastest)
Vector – Synchronized, only slightly slower in tests of sizes under 100000
Stack – Synchronized, same speed as Vector, LIFO queue
LinkedList – Unsynchronized, allows two way iteration and modification of items (like a stack or queue)
CopyOnWriteArrayList – Synchronized, significantly slower in tests of large numbers of items or average list changes, only slightly slower when used with very small numbers (<100)>

Set – this a set of items with no duplicates (no two items can compare as equal), ordering is typically inconsistent over multiple set iterations depending on the implementation but you should assume the order is effectively random unless the set specifies ordered iteration, generally ok to iterate and fast to do lookups

HashSet – Unsychronized (fastest), slower than HashMap which it is built on, allows nulls
LinkedHashSet – Unsychronized, ordered by insertion, allows nulls
TreeSet – Unsychronized, ordered by the natural ordering of the items or a comparator provided at construction, allows nulls but there are issues with removing them
CopyOnWriteArraySet – Synchronized, significantly slower in tests of large numbers of items or average set changes, only slightly slower when used with very small numbers (<100)>

Map – Stores key/value pairs (maps keys to values) where the keys must be unique, order of iteration over keys, values, or pairs is highly dependent on the implementation of the map, allowed nulls also vary by implementation, generally very fast to lookup keys and slow to lookup values

IdentityHashMap – Unsychronized (fastest), uses reference equality (==) instead of object equality (equals) to compare keys, actually violates the Map interface guarantee, all iterators are unordered, allows null keys and values
HashMap – Unsychronized, this is the fastest general purpose map, all iterators are unordered, allows null keys and values
ConcurrentHashMap – Synchronized, all iterators are unordered, does not allow null keys or values
Hashtable – Synchronized, all iterators are unordered, does not allow null keys or values
LinkedHashMap – Unsychronized, all iterators are ordered based on insertion order of the original key (does not change if a key is reinserted), allows null values but null keys are not allowed
TreeMap – Unsychronized, iterators are ordered by the natural or comparator ordering of the keys, allows null keys and values but the comparator needs to understand them

Java Collections Framework (JCF)成员主要包括两种类型,即:Collection和Map类型。 在Java中提供了Collection和Map接口。其中List和Set继承了Collection接口;同时用Vector、ArrayList、 LinkedList三个类实现List接口,HashSet、TreeSet实现Set接口。直接有HashTable、HashMap、 TreeMap实现Map接口。

List

Vector基于Array的List,性能也就不可能超越Array,并且Vector是sychronized的,这个也是Vector和ArrayList的唯一的区别。
ArrayList:同Vector一样是一个基于Array的,但是不同的是ArrayList不是同步的。所以在性能上要比Vector优越一些,但是当运行到多线程环境中时,可需要自己在管理线程的同步问题。从其命名中可以看出它是一种类似数组的形式进行存储,因此它的随机访问速度极快。
LinkedList:LinkedList不同于前面两种List,它不是基于Array的,所以不受Array性能的限制。它每一个节点(Node)都包含两方面的内容:1.节点本身的数据(data);2.下一个节点的信息(nextNode)。所以当对LinkedList做添加,删除动作的时候就不用像基于Array的List一样,必须进行大量的数据移动。只要更改nextNode的相关信息就可以实现了所以它适合于进行频繁进行插入和删除操作。这就是LinkedList的优势。Iterator只能对容器进行向前遍历,而 ListIterator则继承了Iterator的思想,并提供了对List进行双向遍历的方法。

List总结:

所有的List中只能容纳单个不同类型的对象组成的表,而不是Key-Value键值对。
所有的List中可以有相同的元素。
所有的List中可以有null元素。
基于Array的List(Vector,ArrayList)适合查询,而LinkedList(链表)适合添加,删除操作。

Set

HashSet:虽然Set同List都实现了Collection接口,但是他们的实现方式却大不一样。List基本上都是以Array为基础。但是 Set则是在HashMap的基础上来实现的,这个就是Set和List的根本区别。HashSet的存储方式是把HashMap中的Key作为Set的对应存储项,这也是为什么在Set中不能像在List中一样有重复的项的根本原因,因为HashMap的key是不能有重复的。HashSet能快速定位一个元素,但是放到HashSet中的对象需要实现hashCode()方法0。
TreeSet则将放入其中的元素按序存放,这就要求你放入其中的对象是可排序的,这就用到了集合框架提供的另外两个实用类Comparable和 Comparator。一个类是可排序的,它就应该实现Comparable接口。有时多个类具有相同的排序算法,那就不需要重复定义相同的排序算法,只要实现Comparator接口即可。TreeSet是SortedSet的子类,它不同于HashSet的根本就是TreeSet是有序的。它是通过SortedMap来实现的。

Set总结:

Set实现的基础是Map(HashMap)
Set中的元素是不能重复的,如果使用add(Object obj)方法添加已经存在的对象,则会覆盖前面的对象; Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别? Set里的元素是不能重复的,即不能包含两个元素e1、e2(e1.equals(e2))。那么用iterator()方法来区分重复与否。 equals()是判读两个Set是否相等。==方法决定引用值(句柄)是否指向同一对象。

Map

Map是一种把键对象和值对象进行关联的容器,Map有两种比较常用的实现: HashTable、HashMap和TreeMap。

HashMap也用到了哈希码的算法,以便快速查找一个键TreeMap则是对键按序存放,因此它有一些扩展的方法,比如 firstKey(),lastKey()等。

HashMap和Hashtable的区别

HashMap是Hashtable的轻量级实现(非线程安全的实现),他们都完成了Map接口。主要区别在于HashMap允许空(null)键(key)或值(value),非同步,由于非线程安全,效率上可能高于Hashtable。 Hashtable不允许空(null)键(key)或值(value),Hashtable的方法是Synchronize的,在多个线程访问Hashtable时,不需要自己为它的方法实现同步,而HashMap就必须为之提供外同步。 Hashtable和HashMap采用的hash/rehash算法都大致一样,所以性能不会有很大的差异。

2012年1月1日 | 归档于 Java

WP-CodeBox所支持的所有语言

Usage

Example 1: PHP, no line numbers

<pre lang="php">
<?php
  function foo() {
    echo "Hello World!\\n";
  }
  for (\$i = 0; \$i < 10 $i++) {
    foo();
  }
?>

Example 2: Java, with line numbers,collapse codebox

1
2
3
4
5
6
<pre lang="java" line="1" colla="-">
public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}

Example 3: Ruby, with line numbers starting at 18, code downloading(ruby.txt)

18
19
20
21
22
23
<pre lang="ruby" line="18" file="ruby.txt">
class Example
  def example(arg1)
    return "Hello: " + arg1.to_s
  end
end

Supported Languages

The following languages are supported in the lang attribute:

abap, actionscript, ada, apache, applescript, asm, asp, autoit, bash, blitzbasic, bnf, c, c_mac, caddcl, cadlisp, cfdg, cfm, cpp-qt, cpp, csharp, css, d, delphi, diff, div, dos, dot, eiffel, fortran, freebasic, genero, gml, groovy, haskell, html4strict, idl, ini, inno, io, java, java5, javascript, latex, lisp, lua, m68k, matlab, mirc, mpasm, mysql, nsis, objc, ocaml-brief, ocaml, oobas, oracle8, pascal, per, perl, php-brief, php, plsql, python, qbasic, rails, reg, robots, ruby, sas, scheme, sdlbasic, smalltalk, smarty, sql, tcl, text, thinbasic, tsql, vb, vbnet, vhdl, visualfoxpro, winbatch, xml, xpp, z80

2012年1月1日 | 归档于 软件工程

Java和C#利用DES算法加密和解密数据

今天晚上折腾了很久,一直在想, .NET 的 DES算法 加密的数据 JAVA能解吗,看了下 微软的SDK帮助文档,其实就是一个加密算法,只要知道IV和KEY就能解密数据.
C# SDK API地址:

http://msdn.microsoft.com/zh-cn/library/system.security.cryptography.descryptoserviceprovider%28v=VS.80%29.aspx

.NET加密实现(iv我用一个byte数组,值是1-8)

1
2
3
4
5
6
7
8
9
10
11
12
public static string EncryptDES(string encryptString, string encryptKey)
{
    DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
    byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey);
    byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
    MemoryStream mStream = new MemoryStream();
    CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, new byte[]{1,2,3,4,5,6,6,7,8}), CryptoStreamMode.Write);
    cStream.Write(inputByteArray, 0, inputByteArray.Length);
    cStream.FlushFinalBlock();
 
    return Convert.ToBase64String(mStream.ToArray());
}

.NET解密实现(解密的key和iv一定要一样,否则解密失败)

1
2
3
4
5
6
7
8
9
10
11
public static string DecryptDES(string decryptString, string decryptKey)
{
    byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey);
    byte[] inputByteArray = Convert.FromBase64String(decryptString);
    DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
    MemoryStream mStream = new MemoryStream();
    CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, new byte[]{1,2,3,4,5,6,6,7,8}), CryptoStreamMode.Write);
    cStream.Write(inputByteArray, 0, inputByteArray.Length);
    cStream.FlushFinalBlock();
    return Encoding.UTF8.GetString(mStream.ToArray());
}

下面是JAVA版的
JAVA加密:

1
2
3
4
5
6
7
8
9
public static String encryptDES(String encryptString, String encryptKey) throws Exception {
	IvParameterSpec zeroIv = new IvParameterSpec(new byte[8]);
	SecretKeySpec key = new SecretKeySpec(encryptKey.getBytes(), "DES");
	Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
	cipher.init(Cipher.ENCRYPT_MODE, key, zeroIv);
	byte[] encryptedData = cipher.doFinal(encryptString.getBytes());
 
	return new BASE64Encoder().encode(encryptedData);
}

java解密:

1
2
3
4
5
6
7
8
9
public static String decryptDES(String decryptString, String decryptKey) throws Exception {
	byte[] byteMi = new BASE64Decoder().decodeBuffer(decryptString);
	IvParameterSpec zeroIv = new IvParameterSpec(new byte[8]);
	SecretKeySpec key = new SecretKeySpec(decryptKey.getBytes(), "DES");
	Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
	cipher.init(Cipher.DECRYPT_MODE, key, zeroIv);
	byte decryptedData[] = cipher.doFinal(byteMi);
	return new String(decryptedData);
}

另外再贴上两个装换工具
java版:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public static byte[] convertHexString(String ss)    
    {    
    byte digest[] = new byte[ss.length() / 2];    
    for(int i = 0; i < digest.length; i++)    
    {    
    String byteString = ss.substring(2 * i, 2 * i + 2);    
    int byteValue = Integer.parseInt(byteString, 16);    
    digest[i] = (byte)byteValue;    
    }    
 
    return digest;    
    } 
 
public static String toHexString(byte b[]) {   
        StringBuffer hexString = new StringBuffer();   
        for (int i = 0; i < b.length; i++) {   
            String plainText = Integer.toHexString(0xff & b[i]);   
            if (plainText.length() < 2)   
                plainText = "0" + plainText;   
            hexString.append(plainText);   
        }   
 
        return hexString.toString();   
    }

C#版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 private static string ToHexString(string str)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            string temp = "";
            for (int i = 0; i < bytes.Length; i++)
            {
                int inttemp = (int)bytes[i];
                temp += Convert.ToString((byte)inttemp, 16);
            }
            return temp;
        }
 
     private static string HexToString(string str)
        {
            // byte[] bytes = Encoding.UTF8.GetBytes(str);
            byte[] buff = new byte[str.Length / 2];
            for (int i = 0; i < buff.Length; i++)
            {
 
                buff[i] = (byte)((int)byte.Parse(str.Substring(i * 2, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
            }
            string aa = Encoding.UTF8.GetString(buff);
            return aa;
        }

Java中十进制和十六进制互转

// 十进制转化为十六进制
Integer.toHexString(200);

// 十六进制转化为十进制
Integer.parseInt(“8C”,16);

2012年1月1日 | 归档于 Java

Java读取Properties文件多种方法

1。使用java.util.Properties类的load()方法
示例: InputStream in = lnew BufferedInputStream(new FileInputStream(name));
Properties p = new Properties();
p.load(in);

2。使用java.util.ResourceBundle类的getBundle()方法
示例: ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());

3。使用java.util.PropertyResourceBundle类的构造函数
示例: InputStream in = new BufferedInputStream(new FileInputStream(name));
ResourceBundle rb = new PropertyResourceBundle(in);

4。使用class变量的getResourceAsStream()方法
示例: InputStream in = JProperties.class.getResourceAsStream(name);
Properties p = new Properties();
p.load(in);

5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法
示例: InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name);
Properties p = new Properties();
p.load(in);

6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法
示例: InputStream in = ClassLoader.getSystemResourceAsStream(name);
Properties p = new Properties();
p.load(in);

补充

Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法
示例:InputStream in = context.getResourceAsStream(path);
Properties p = new Properties();
p.load(in);

如果在静态方法中好像只能使用ClassLoader.getSystemResourceAsStream(name);

2011年12月29日 | 归档于 Java

godaddy域名续费优惠码

1、.INFO域名
优惠码:gdbbren8,6.99美元续费;
优惠码:gdbb776,6.99美元续费;

 

2、.NET域名
优惠码:gdbbren8,7.50美元续费;
优惠码:gdbb776,7.50美元续费;

 

3、.ORG域名
优惠码:scam14,7.49美元续费;
优惠码:gdbbren8,7.50美元续费;
优惠码:gdbb776,7.50美元续费;

 

4、.BIZ域名
优惠码:emfb7,7.49美元续费;

 

5、.COM域名
优惠码:gdbbren8,7.99美元续费;
优惠码:gdbb776,7.99美元续费。

 

现在就去GoDaddy探明真相吧:http://www.godaddy.com/

 

PS: 3月24号更新:
godaddy续费.info只要 6.99美元,续费.net和.org只要7.50美元,续费.com只要7.99美元,需要另外加上18美分的税费
截止时期:2011年4月1日
优惠码:gdbbren8   和  gdbb776 两枚

2011年12月4日 | 归档于 生活闲谈

再议开源协议的比较

现今存在的开源协议很多,而经过Open Source Initiative组织通过批准的开源协议目前有58种(http://www.opensource.org/licenses/alphabetical)。我们在常见的开源协议如BSD, GPL, LGPL,MIT等都是OSI批准的协议。如果要开源自己的代码,最好也是选择这些被批准的开源协议。

BSD开源协议(original BSD license、FreeBSD license、Original BSD license)

BSD开源协议是一个给于使用者很大自由的协议。基本上使用者可以”为所欲为”,可以自由的使用,修改源代码,也可以将修改后的代码作为开源或者专有软件再发布。

但”为所欲为”的前提当你发布使用了BSD协议的代码,或则以BSD协议代码为基础做二次开发自己的产品时,需要满足三个条件:

如果再发布的产品中包含源代码,则在源代码中必须带有原来代码中的BSD协议。
如果再发布的只是二进制类库/软件,则需要在类库/软件的文档和版权声明中包含原来代码中的BSD协议。
不可以用开源代码的作者/机构名字和原来产品的名字做市场推广。
BSD 代码鼓励代码共享,但需要尊重代码作者的著作权。BSD由于允许使用者修改和重新发布代码,也允许使用或在BSD代码上开发商业软件发布和销售,因此是对商业集成很友好的协议。而很多的公司企业在选用开源产品的时候都首选BSD协议,因为可以完全控制这些第三方的代码,在必要的时候可以修改或者二次开发。

Apache Licence 2.0(Apache License, Version 2.0、Apache License, Version 1.1、Apache License, Version 1.0)

Apache Licence是著名的非盈利开源组织Apache采用的协议。该协议和BSD类似,同样鼓励代码共享和尊重原作者的著作权,同样允许代码修改,再发布(作为开源或商业软件)。需要满足的条件也和BSD类似:

需要给代码的用户一份Apache Licence
如果你修改了代码,需要再被修改的文件中说明。
在延伸的代码中(修改和有源代码衍生的代码中)需要带有原来代码中的协议,商标,专利声明和其他原来作者规定需要包含的说明。
如果再发布的产品中包含一个Notice文件,则在Notice文件中需要带有Apache Licence。你可以在Notice中增加自己的许可,但不可以表现为对Apache Licence构成更改。
Apache Licence也是对商业应用友好的许可。使用者也可以在需要的时候修改代码来满足需要并作为开源或商业产品发布/销售。

GPL(GNU General Public License)

我们很熟悉的Linux就是采用了GPL。GPL协议和BSD, Apache Licence等鼓励代码重用的许可很不一样。GPL的出发点是代码的开源/免费使用和引用/修改/衍生代码的开源/免费使用,但不允许修改后和衍生的代码做为闭源的商业软件发布和销售。这也就是为什么我们能用免费的各种linux,包括商业公司的linux和linux上各种各样的由个人,组织,以及商业软件公司开发的免费软件了。

GPL协议的主要内容是只要在一个软件中使用(“使用”指类库引用,修改后的代码或者衍生代码)GPL 协议的产品,则该软件产品必须也采用GPL协议,既必须也是开源和免费。这就是所谓的”传染性”。GPL协议的产品作为一个单独的产品使用没有任何问题,还可以享受免费的优势。

由于GPL严格要求使用了GPL类库的软件产品必须使用GPL协议,对于使用GPL协议的开源代码,商业软件或者对代码有保密要求的部门就不适合集成/采用作为类库和二次开发的基础。

其它细节如再发布的时候需要伴随GPL协议等和BSD/Apache等类似。

LGPL(GNU Lesser General Public License)

LGPL是GPL的一个为主要为类库使用设计的开源协议。和GPL要求任何使用/修改/衍生之GPL类库的的软件必须采用GPL协议不同。LGPL允许商业软件通过类库引用(link)方式使用LGPL类库而不需要开源商业软件的代码。这使得采用LGPL协议的开源代码可以被商业软件作为类库引用并发布和销售。

但是如果修改LGPL协议的代码或者衍生,则所有修改的代码,涉及修改部分的额外代码和衍生的代码都必须采用LGPL协议。因此LGPL协议的开源代码很适合作为第三方类库被商业软件引用,但不适合希望以LGPL协议代码为基础,通过修改和衍生的方式做二次开发的商业软件采用。

GPL/LGPL都保障原作者的知识产权,避免有人利用开源代码复制并开发类似的产品

MIT(MIT)

MIT是和BSD一样宽范的许可协议,作者只想保留版权,而无任何其他了限制.也就是说,你必须在你的发行版里包含原许可协议的声明,无论你是以二进制发布的还是以源代码发布的.

2011年11月28日 | 归档于 Java, 软件工程

Parameters: Invalid chunk ” ignored.

出现这个警告主要是由于 url连接中 有额外的连接符,例如

abc.com/login.jsp&a=1 或 abc.com/login.do&uname=a

上面两个连接 都多了一个 & ,发布到web服务器后 会报 Parameters: Invalid chunk ” ignored. 这个警告,

解决办法就是把这个多余的&去掉即可。

2011年11月20日 | 归档于 Java

mysql高效使用rownum分页

mysql最方便的分页是使用limit方式,但是如果要实现mysql和oracle数据库的统一,可以把mysql的limit方式改为rownum.
网上也有其他帖子介绍mysql的rownum实现,包括连接查询和子查询,但是效率都不是很好,使用rownum方式效率一般但是如果connection一直连接就无法查询数据,今天把这个问题解决了。sql实现如下:

select @rownum:=@rownum+1 ‘rank’, p.* from player p, (SELECT @rownum:=0) r order by money desc;

注意:(SELECT @rownum:=0) r 这句是清除@rownum数据,是不能去掉的。

2011年11月19日 | 归档于 Java, Mysql