Here you can find the source of createUpdateStatement(Connection conn, String databaseName, String[] fieldsToUpdate, String[] selectionFields)
protected static PreparedStatement createUpdateStatement(Connection conn, String databaseName, String[] fieldsToUpdate, String[] selectionFields) throws SQLException
//package com.java2s; /**/* w w w . jav a2s. c o m*/ * ClarescoExperienceAPI * Copyright * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * Please contact Claresco, www.claresco.com, if you have any questions. **/ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; public class Main { protected static PreparedStatement createUpdateStatement(Connection conn, String databaseName, String[] fieldsToUpdate, String[] selectionFields) throws SQLException { String updateString = createUpdateString(databaseName, fieldsToUpdate, selectionFields); return conn.prepareStatement(updateString); } private static String createUpdateString(String databaseName, String[] fieldsToUpdate, String[] selectionFields) { String baseString = "update %s set %s where %s;"; String setFieldsString = ""; for (String s : fieldsToUpdate) { setFieldsString += s + " = ?, "; } setFieldsString = setFieldsString.substring(0, setFieldsString.length() - 2); //System.out.println(setFieldsString); String selectionString = ""; for (String s : selectionFields) { selectionString += s + " = ? and "; } selectionString = selectionString.substring(0, selectionString.length() - 4); //System.out.println(selectionString); return String.format(baseString, databaseName, setFieldsString, selectionString); } }