How to update database through CSV for some columns
问题
https://stackoverflow.com/questions/70380362/how-to-update-database-through-csv-for-some-columns
i have table in which there are columns like id, link_name ,browser_title ,title ,content etc..
which contain the relevant information now i have the file CSV which contains new title and browser_title values for some link _names(CSV looks like -- link_name, title, browser_title) now i have to update the values for title and browser_title .
can anyone suggest what should be the good way to do that
解答
这个问题需要使用csv文件中的数据更新数据库表中的部分数据。直接用JAVA一般要入库临时表再更新,很麻烦。
用Java下的开源包SPL很容易写,只要1句:
A |
|
1 |
=RDB.update@u(file("update_info.csv").import@ct(),infotable,link_name,title,browser_title) |
SPL提供了JDBC供JAVA调用,把上面的脚本存为update.splx,在JAVA中以存储过程的方式调用就可以了:
…
Class.forName("com.esproc.jdbc.InternalDriver");
con = DriverManager.getConnection("jdbc:esproc:local://");
st = con.prepareCall("call update ()");
st.execute();
…
或在JAVA中以SQL方式直接执行SPL串:
…
st = con.prepareStatement("==RDB.update@u(file(\"update_info.csv\").import@ct(),infotable,link_name,title,browser_title)");
st.execute();
…
English version