Text File Read and Write to Database
【Question】
eBay http://www.ebay360.com.cn 2;
OCJ http://www.ocj.com.c 2;
51 Buy http://www.51buy.co 2;
Paipai http://www.paipai.com 2;
Suning http://www.suning.com 2;
Amazon http://www.amazon.cn/ 2;
Vipshop http://www.vipshop.com 2;
GOME http://www.gome.com.cn 2;
Dangdang http://www.dangdang.com 2;
I need to write the above data to the database. Write website names to name field, urls to url field, and the number 2 to status. Could anyone tell me how to parse this?
【Answer】
It’s simple to parse the text data and update it to the database in Java. But the code is long. To get more concise code, you can do it in SPL (Structured Process Language). The SPL script can be conveniently embedded into the Java application (See How to Call an SPL Script in Java)to learn more).Here’s the SPL script:
A |
|
1 |
=file(“E:\\source.txt”).import() |
2 |
=A1.run(_3=left(_3,-1)) |
3 |
>db.update(A1,tableName,name:_1,url:_2,status:_3) |
A1: Import the text file source.txt as rows and columns;
A2: Remove the semicolons after number 2;
A3: Write A1’s data to the database.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL