是否有任何JDBC驅動程序支持LOAD DATA INFILE sql命令? - Does any JDBC driver supports LOAD DATA INFILE sql command? -开发者知识库

是否有任何JDBC驅動程序支持LOAD DATA INFILE sql命令? - Does any JDBC driver supports LOAD DATA INFILE sql command? -开发者知识库,第1张

Hi I would like to create table through JDBC on multiple databases like DB2, Sybase, MySQL etc. Now I need to create this table using text file say data.txt which contains data space separated values. For e.g.

您好我想通過JDBC在DB2,Sybase,MySQL等多個數據庫上創建表。現在我需要使用文本文件創建此表,例如data.txt,其中包含數據空間分隔值。對於例如

CustName OrderNo PhoneNo

XYZ      230     123456789
ABC      450     879641238    

Now this data.txt contains thousands of records space separated values. I need to parse this file line by line using java io and execute sql insert queries for each records.

現在這個data.txt包含數千個記錄空間分隔值。我需要使用java io逐行解析這個文件,並為每個記錄執行sql insert查詢。

I found there is LOAD DATA INFILE sql command. Does any JDBC driver supports this command? If not what should be the best efficient fast approach to solve this problem.

我發現有LOAD DATA INFILE sql命令。是否有任何JDBC驅動程序支持此命令?如果不是什么應該是解決這個問題的最有效的快速方法。

Please guide. Thanks in advance.

請指導。提前致謝。

4 个解决方案

#1


8  

The following will work through JDBC. Note that to use LOAD DATA INFILE you need superuser privilege. Which you don't need for LOAD DATA LOCAL INFILE

以下內容將通過JDBC完成。請注意,要使用LOAD DATA INFILE,您需要超級用戶權限。您不需要LOAD DATA LOCAL INFILE

Connection con = DriverManager.getConnection("jdbc:mysql://localhost/foobar", "root", "password");
Statement stmt = con.createStatement();
String sql = 
    "load data infile 'c:/temp/some_data.txt' \n"  
    "   replace \n"  
    "   into table prd \n"  
    "   columns terminated by '\t' \n"  
    "   ignore 1 lines";
stmt.execute(sql);

If you use LOAD DATA INFILE the file location is based on the server's filesystem! If you use a local file, then obviously it's based on the client's filesystem.

如果使用LOAD DATA INFILE,文件位置基於服務器的文件系統!如果您使用本地文件,那么顯然它基於客戶端的文件系統。

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复