Example usage for java.sql PreparedStatement setShort

List of usage examples for java.sql PreparedStatement setShort

Introduction

In this page you can find the example usage for java.sql PreparedStatement setShort.

Prototype

void setShort(int parameterIndex, short x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java short value.

Usage

From source file:com.symantec.wraith.silo.sql.TestSQLRulesStore.java

@Before
public void before() throws SQLException, IOException {
    System.setProperty("derby.stream.error.field", DerbyUtil.class.getCanonicalName() + ".DEV_NULL");
    File db = new File(TARGET_RULES_DB);
    if (db.exists()) {
        System.out.println("Deleting database");
        FileUtils.deleteDirectory(db);// w ww  . j av  a  2s .  co m
    }
    String createTable = "create table testRules(" + SQLRulesStore.COLUMN_RULE_ID + " smallint primary key,"
            + SQLRulesStore.COLUMN_RULE_CONTENT + " varchar(3000))";
    runSQL(CONNECTION_STRING, createTable);

    Condition condition = new JavaRegexCondition("tst", "\\d+");
    Action action = new TemplatedAlertAction((short) 2, (short) 2);
    Rule testRule = new SimpleRule((short) 1233, "testRule", true, condition, action);

    Connection conn = DriverManager.getConnection(CONNECTION_STRING);
    PreparedStatement insert = conn.prepareStatement("insert into testRules values(?, ?)");
    insert.setShort(1, testRule.getRuleId());
    insert.setString(2, RuleSerializer.serializeRuleToJSONString(testRule, false));
    insert.execute();
    conn.close();
}

From source file:net.freechoice.model.orm.Map_Post.java

/**
 * for content update see Dao_Post//from w  w  w.  j a v  a 2  s  .  co m
 */
@Override
public PreparedStatementCreator createUpdate(final FC_Post entity) {

    return new PreparedStatementCreator() {
        @Override
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

            PreparedStatement ps = con.prepareStatement(" update  FC_Post " + " set   status = ?,"
                    + "     id_author = ?, " + "     name_author = ?, " + "     title = ? " + " where id = ? ");
            ps.setShort(1, entity.status);
            ps.setInt(2, entity.id_author);
            ps.setString(3, entity.name_author);
            ps.setString(4, entity.title);
            ps.setInt(5, entity.id);
            return ps;
        }
    };
}

From source file:com.wabacus.system.datatype.ShortType.java

public void setPreparedStatementValue(int iindex, String value, PreparedStatement pstmt, AbsDatabaseType dbtype)
        throws SQLException {
    log.debug("setShort(" + iindex + "," + value + ")");
    Object objTmp = label2value(value);
    if (objTmp == null) {
        pstmt.setObject(iindex, null, java.sql.Types.SMALLINT);
    } else {/*from   ww w . j a va  2s . c o m*/
        pstmt.setShort(iindex, (Short) objTmp);
    }
}

From source file:net.freechoice.model.orm.Map_Post.java

@Override
public PreparedStatementCreator createInsert(final FC_Post post) {

    return new PreparedStatementCreator() {

        @Override/*from  ww w  .j  a va 2 s .  com*/
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement ps = con
                    .prepareStatement(
                            "insert into FC_Post(" + "status," + "id_author," + "name_author," + "title,"
                                    + "content," + "search_vector)" + "values(?,?,?,?,?, to_tsvector(? || ?)) ",
                            RET_ID);
            ps.setShort(1, post.status);
            ps.setInt(2, post.id_author);
            ps.setString(3, post.name_author);
            ps.setString(4, post.title);
            ps.setString(5, post.content);
            ps.setString(6, post.title);
            ps.setString(7, post.content);
            return ps;
        }
    };
}

From source file:com.chenxin.authority.common.logback.DBAppender.java

/**
 * Add an exception statement either as a batch or execute immediately if
 * batch updates are not supported.//from w  w w . j a v a  2  s  .  c  o m
 */
void updateExceptionStatement(PreparedStatement exceptionStatement, String txt, short i, long eventId)
        throws SQLException {
    exceptionStatement.setLong(1, eventId);
    exceptionStatement.setShort(2, i);
    exceptionStatement.setString(3, txt);
    if (cnxSupportsBatchUpdates) {
        exceptionStatement.addBatch();
    } else {
        exceptionStatement.execute();
    }
}

From source file:de.erdesignerng.dialect.oracle.OracleReverseEngineeringStrategy.java

@Override
protected void reverseEngineerIndexAttribute(DatabaseMetaData aMetaData, TableEntry aTableEntry, Table aTable,
        ReverseEngineeringNotifier aNotifier, Index aIndex, String aColumnName, short aPosition,
        String aAscOrDesc) throws SQLException, ReverseEngineeringException {

    // This needs only to be checked if it is a function based index
    if (!aColumnName.endsWith("$")) {
        super.reverseEngineerIndexAttribute(aMetaData, aTableEntry, aTable, aNotifier, aIndex, aColumnName,
                aPosition, aAscOrDesc);// w  w  w .  ja  va2 s  . c  o  m
        return;
    }

    Connection theConnection = aMetaData.getConnection();
    PreparedStatement theStatement = theConnection.prepareStatement(
            "SELECT * FROM USER_IND_EXPRESSIONS WHERE INDEX_NAME = ? AND TABLE_NAME = ? AND COLUMN_POSITION = ?");
    theStatement.setString(1, aIndex.getOriginalName());
    theStatement.setString(2, aTable.getOriginalName());
    theStatement.setShort(3, aPosition);
    ResultSet theResult = theStatement.executeQuery();
    boolean found = false;
    while (theResult.next()) {
        found = true;
        String theColumnExpression = theResult.getString("COLUMN_EXPRESSION");

        aIndex.getExpressions().addExpressionFor(theColumnExpression);
    }
    theResult.close();
    theStatement.close();
    if (!found) {
        throw new ReverseEngineeringException("Cannot find index column information for " + aColumnName
                + " index " + aIndex.getName() + " table " + aTable.getName());
    }
}

From source file:org.wso2.carbon.user.core.util.DatabaseUtil.java

public static void updateDatabase(Connection dbConnection, String sqlStmt, Object... params)
        throws UserStoreException {
    PreparedStatement prepStmt = null;
    try {// w  ww .  j a v a  2 s.c  om
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        if (params != null && params.length > 0) {
            for (int i = 0; i < params.length; i++) {
                Object param = params[i];
                if (param == null) {
                    //allow to send null data since null allowed values can be in the table. eg: domain name
                    prepStmt.setString(i + 1, null);
                    //throw new UserStoreException("Null data provided.");
                } else if (param instanceof String) {
                    prepStmt.setString(i + 1, (String) param);
                } else if (param instanceof Integer) {
                    prepStmt.setInt(i + 1, (Integer) param);
                } else if (param instanceof Short) {
                    prepStmt.setShort(i + 1, (Short) param);
                } else if (param instanceof Date) {
                    Date date = (Date) param;
                    Timestamp time = new Timestamp(date.getTime());
                    prepStmt.setTimestamp(i + 1, time);
                }
            }
        }
        prepStmt.executeUpdate();
    } catch (SQLException e) {
        String errorMessage = "Using sql : " + sqlStmt + " " + e.getMessage();
        if (log.isDebugEnabled()) {
            log.debug(errorMessage, e);
        }
        throw new UserStoreException(errorMessage, e);
    } finally {
        DatabaseUtil.closeAllConnections(null, prepStmt);
    }
}

From source file:org.wso2.carbon.user.core.profile.dao.ProfileConfigDAO.java

private void addToAddBatch(List<String> lst, int profileId, Map<String, Integer> ids, short behavior,
        PreparedStatement prepStmt) throws SQLException {
    for (Iterator<String> ite = lst.iterator(); ite.hasNext();) {
        String claimUri = ite.next();
        if (claimUri == null || ids.get(claimUri) == null) {
            continue;
        }//from  w  ww  .j  a v  a2s .co m
        prepStmt.setInt(1, profileId); //profName
        prepStmt.setInt(2, ids.get(claimUri));
        prepStmt.setShort(3, behavior);
        prepStmt.setInt(4, tenantId);
        prepStmt.addBatch();
    }
}

From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java

public void updateIaAddr(final IaAddress iaAddr) {
    getJdbcTemplate().update("update dhcplease" + " set state = ?,"
            + ((iaAddr instanceof IaPrefix) ? " prefixlen = ?," : "") + " starttime = ?,"
            + " preferredendtime = ?," + " validendtime = ?" + " where ipaddress = ?",
            new PreparedStatementSetter() {
                @Override/*from  w  ww . ja  v a  2  s  .  c  o m*/
                public void setValues(PreparedStatement ps) throws SQLException {
                    int i = 1;
                    ps.setByte(i++, iaAddr.getState());
                    if (iaAddr instanceof IaPrefix) {
                        ps.setShort(i++, ((IaPrefix) iaAddr).getPrefixLength());
                    }
                    Date start = iaAddr.getStartTime();
                    if (start != null) {
                        java.sql.Timestamp sts = new java.sql.Timestamp(start.getTime());
                        ps.setTimestamp(i++, sts, Util.GMT_CALENDAR);
                    } else {
                        ps.setNull(i++, java.sql.Types.TIMESTAMP);
                    }
                    Date preferred = iaAddr.getPreferredEndTime();
                    if (preferred != null) {
                        java.sql.Timestamp pts = new java.sql.Timestamp(preferred.getTime());
                        ps.setTimestamp(i++, pts, Util.GMT_CALENDAR);
                    } else {
                        ps.setNull(i++, java.sql.Types.TIMESTAMP);
                    }
                    Date valid = iaAddr.getValidEndTime();
                    if (valid != null) {
                        java.sql.Timestamp vts = new java.sql.Timestamp(valid.getTime());
                        ps.setTimestamp(i++, vts, Util.GMT_CALENDAR);
                    } else {
                        ps.setNull(i++, java.sql.Types.TIMESTAMP);
                    }
                    ps.setBytes(i++, iaAddr.getIpAddress().getAddress());
                }
            });
}

From source file:de.erdesignerng.dialect.msaccess.MSAccessReverseEngineeringStrategy.java

/**
 * Returns a ResultSet containing all records that represent a specified
 * attribute of a query.//from   w  w  w  .j  av  a  2s.  co m
 *
 * @param aConnection
 * @param aViewName
 * @param theAttributeID
 * @return ResultSet containing all records that represent a specified attribute
 * @throws java.sql.SQLException
 */
private ResultSet getSQLProperties(Connection aConnection, String aViewName, Short theAttributeID)
        throws SQLException {
    String theQuery = "SELECT MSysQueries.* "
            + "FROM MSysQueries LEFT JOIN MSysObjects ON MSysQueries.ObjectId = MSysObjects.Id "
            + "WHERE ((MSysObjects.Name = ?) AND (MSysQueries.Attribute = ?));";

    PreparedStatement theStatement;
    ResultSet theQueryProperties;

    theStatement = aConnection.prepareStatement(theQuery);
    theStatement.setString(1, aViewName);
    theStatement.setShort(2, theAttributeID);

    theQueryProperties = theStatement.executeQuery();

    return theQueryProperties;
}