[英]Read two different arrayList value in java and add it to a same array Object
I am trying to create update sql query from csv file. 我正在尝试从csv文件创建更新sql查询。
So, for that I am trying to read two different array list value, one is coming from CSV file and other one is coming from database. 因此,为此,我尝试读取两个不同的数组列表值,一个来自CSV文件,另一个来自数据库。 I want to update my Books Database but there are some fields which should be as it is.
我想更新我的图书数据库,但是有些字段应该保持原样。
I wrote below piece of code to do that and I am able to print the query, however I feel my code is not efficient. 我写了下面的代码来做到这一点,并且能够打印查询,但是我觉得我的代码效率不高。 I could have done this in a more efficient way like instead of reading indexes.
我本可以以更有效的方式完成此任务,而不是读取索引。
public List<Book> generateSqlQuery(List<Book> booksFromCSV) throws Exception{
String update_query = "UPDATE Books SET book_name={0}, author_name={1}";
String updateQuery = null;
Object [] book = null;
MessageFormat messageFormat = new MessageFormat(update_query);
List<Book> booksFromDB = BookDao.getBooks();
for(int i=0; i<booksFromCSV.size()-1; i++){
book = new Object[] { booksFromDB.get(i).getBookName(),
booksFromCSV.get(i).getAuthorName()};
updateQuery = messageFormat.format(book);
System.out.println(updateQuery);
}
return booksFromCSV;
}
Please give me some advice or different approaches, of how to read two different arraylist value and keep it in same array. 请给我一些建议或不同的方法,关于如何读取两个不同的arraylist值并将其保存在同一数组中。
I apologize in advance for the grammar mistake or any other mistake. 对于语法错误或任何其他错误,我事先表示歉意。
This could create scenarios of SQL Injection. 这可能会创建SQL注入方案。 Use bind variables and loop against the list.
使用绑定变量并针对列表进行循环。 If you do believe there are chances of a long list, you can try batch update.
如果您确实认为列表很长,可以尝试批量更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.