亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java JDBC Postgres copyIn無法識別行尾并填充雙引號

Java JDBC Postgres copyIn無法識別行尾并填充雙引號

一只甜甜圈 2021-07-05 16:31:44
我正在嘗試使用 Java 將數據從 Oracle 加載到 Greenplum。我將結果集作為逗號分隔值存儲到字節數組輸入流中,然后使用 copy in 加載它。import java.sql.*; import au.com.bytecode.opencsv.CSVWriter;import java.io.*;import org.postgresql.copy.CopyManager;import org.postgresql.core.BaseConnection;public class ORtoGP {           public static void main(String[] args) throws SQLException {            try {                String dbURL = "jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = xxxxxx)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = xxxxxx) (SRVR = DEDICATED)))";                String strUserID = "xxxxxx";                String strPassword = "xxxxxx";                Connection myConnection=DriverManager.getConnection(dbURL,strUserID,strPassword);                Statement sqlStatement = myConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);                String readRecordSQL = "select id,name from table where rownum <= 10 ";                ResultSet rs = sqlStatement.executeQuery(readRecordSQL);                 StringWriter stringWriter = new StringWriter();                CSVWriter csvWriter = new CSVWriter(stringWriter);                rs.first();                 csvWriter.writeAll(rs, true);                String orresult = stringWriter.toString();                System.out.println(orresult);                byte[] bytes = orresult.getBytes();                ByteArrayInputStream orinput = new ByteArrayInputStream(bytes);                 String dbURL1 = "jdbc:postgresql://xxxxx:5432/xxxxx";                String user = "xxxx";                String pass = "xxxx";                Connection conn2 = DriverManager.getConnection(dbURL1, user, pass);                CopyManager copyManager = new CopyManager((BaseConnection) conn2);                copyManager.copyIn("copy java_test from stdin with DELIMITER ','",orinput);            }               }    }但是,我遇到了兩個問題:批量加載數據時,進程無法識別行尾。所以它給出了這個錯誤。“錯誤:最后一個預期列之后的額外數據”它還嘗試加載數據,包括值周圍的雙引號。
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

根據文檔,默認格式為text,不處理引用。

您需要FORMAT csv在命令中指定。


查看完整回答
反對 回復 2021-07-14
  • 1 回答
  • 0 關注
  • 412 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號