Java SQL Date Create createUpdateStatement(Connection conn, String databaseName, String[] fieldsToUpdate, String[] selectionFields)

Here you can find the source of createUpdateStatement(Connection conn, String databaseName, String[] fieldsToUpdate, String[] selectionFields)

Description

create Update Statement

License

Open Source License

Declaration

protected static PreparedStatement createUpdateStatement(Connection conn, String databaseName,
            String[] fieldsToUpdate, String[] selectionFields) throws SQLException 

Method Source Code

//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);
    }
}

Related

  1. createDateFormater(int dataType)
  2. createFutureDate(java.sql.Date lmpDate, int offSet)
  3. createRecGetStatementsUpdate(String tip, String imeFirstCap)
  4. createSqlDate(String dateStr)
  5. createStreamingStatement(Connection conn, boolean update)
  6. currentDate()
  7. currentDate()
  8. currentDate()
  9. getCurrDate()