Java SQL PreparedStatement saveResourceInfoRecord(long resourceId, long propertyId, String propertyValue, String userId, PreparedStatement ps)

Here you can find the source of saveResourceInfoRecord(long resourceId, long propertyId, String propertyValue, String userId, PreparedStatement ps)

Description

Private helper method to save a resource info record.

License

Open Source License

Parameter

Parameter Description
resourceId the resource id being saved
propertyId the property id being saved
propertyValue the property value being saved
userId the user saving this record
ps the prepared statement for this insertion

Exception

Parameter Description
SQLException if any error occurs in the underlying layer
RuntimeException if not exactly one record was saved

Declaration

private static void saveResourceInfoRecord(long resourceId, long propertyId, String propertyValue,
        String userId, PreparedStatement ps) throws SQLException, RuntimeException 

Method Source Code

//package com.java2s;

import java.sql.PreparedStatement;

import java.sql.SQLException;

public class Main {
    /**/*from  w w w  .  j a va  2  s .  c o  m*/
     * Private helper method to save a resource info record.
     *
     * @param resourceId the resource id being saved
     * @param propertyId the property id being saved
     * @param propertyValue the property value being saved
     * @param userId the user saving this record
     * @param ps the prepared statement for this insertion
     * @throws SQLException if any error occurs in the underlying layer
     * @throws RuntimeException if not exactly one record was saved
     *
     * @since 1.2
     */
    private static void saveResourceInfoRecord(long resourceId, long propertyId, String propertyValue,
            String userId, PreparedStatement ps) throws SQLException, RuntimeException {

        int index = 1;
        ps.setLong(index++, resourceId);
        ps.setLong(index++, propertyId);
        ps.setString(index++, propertyValue);
        ps.setString(index++, userId);
        ps.setString(index++, userId);
        int nr = ps.executeUpdate();

        if (nr != 1) {
            throw new RuntimeException("Could not create resource info record for id = " + propertyId);
        }
    }
}

Related

  1. prepareStatement(String query)
  2. prepareStatementForwardReadOnly(Connection conn, String name, String sql)
  3. putArgsToStatement(PreparedStatement stmt, List args)
  4. query(List paramList, Connection conn, PreparedStatement pstmt)
  5. runInsertLong(PreparedStatement s)
  6. setByte(PreparedStatement statement, int index, Byte value)
  7. setBytes(PreparedStatement pstmt, int index, byte[] bytes)
  8. setValue(PreparedStatement ps, int paramIndex, Object inValue)
  9. setValue(PreparedStatement ps, int posicion, int tipo, String strDefault, String strValor)

  10. HOME | Copyright © www.java2s.com 2016