最近单位在做oracle向PG数据库的转化.
其中使用到了PG的CopyManager类来做oracle类似的import和export.快速看下PG CopyManager的例子代码:
package test.simple;
//You need to include postgres jdbc jar into your project lib
import org.postgresql.copy.CopyManager;
import org.postgresql.core.BaseConnection;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
import java.io.File;
/**
* Created with IntelliJ IDEA.
* User: leon
* Date: 13-2-5
* Time: 下午12:18
* To change this template use File | Settings | File Templates.
*/
public class TestCopy {
public static void main(String args[])throws Exception{
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost:5432/postgres";
Properties props = new Properties();
props.setProperty("user", "postgres");
props.setProperty("password", "postgres");
Connection conn = DriverManager.getConnection(url, props);
CopyManager cm = new CopyManager((BaseConnection)conn);
File file = new File("a.txt");
if(!file.exists()){
file.createNewFile();
}
/*FileWriter fw = new FileWriter(file);
cm.copyO