List of usage examples for java.sql PreparedStatement setBoolean
void setBoolean(int parameterIndex, boolean x) throws SQLException;
boolean
value. From source file:org.apache.hadoop.hive.ql.metadata.BIStore.java
public int insertInsertExeInfo(Connection cc, Collection<InsertExeInfo> insertInfoList) { if (cc == null || insertInfoList == null || insertInfoList.isEmpty()) { return -1; }/*from ww w . j a v a 2 s. com*/ int rt = -1; PreparedStatement pstmt; String queryID = ""; try { pstmt = cc.prepareStatement( "insert into tdw_insert_info(queryid, desttable, successnum, rejectnum, ismultiinsert) values (?,?,?,?,?)"); for (InsertExeInfo insertInfo : insertInfoList) { queryID = insertInfo.getQueryID(); pstmt.setString(1, insertInfo.getQueryID()); pstmt.setString(2, insertInfo.getDestTable()); pstmt.setLong(3, insertInfo.getFsSuccessNum()); pstmt.setLong(4, insertInfo.getFsRejectNum()); pstmt.setBoolean(5, insertInfo.getIsMultiInsert()); pstmt.addBatch(); } pstmt.executeBatch(); rt = 0; } catch (SQLException e) { LOG.error(" insert INSERT EXE Info failed: " + queryID); e.printStackTrace(); } return rt; }
From source file:com.sinet.gage.dao.DomainsRepository.java
/** * /*w w w . j av a 2s. c o m*/ * @param domains */ public void insertDomains(List<Domain> domains) { try { jdbcTemplate.batchUpdate(DOMAINS_INSERT_SQL, new BatchPreparedStatementSetter() { public int getBatchSize() { if (domains == null) return 0; return domains.size(); } @Override public void setValues(PreparedStatement ps, int i) throws SQLException { Domain domain = domains.get(i); ps.setLong(1, domain.getDomainId()); ps.setObject(2, domain.getGuid()); ps.setString(3, domain.getDomainName()); ps.setString(4, domain.getLoginPrefix()); ps.setLong(5, domain.getFlag()); ps.setString(6, domain.getDomainType()); ps.setLong(7, domain.getParentDomainId()); ps.setString(8, domain.getParentDomainName()); ps.setLong(9, domain.getStateDomainId()); ps.setString(10, domain.getStateDomainName()); ps.setString(11, domain.getLicenseType()); ps.setString(12, domain.getLicensePoolType()); ps.setInt(13, domain.getNoOfLicense()); ps.setBoolean(14, domain.isPilot()); ps.setDate(15, domain.getPilotStartDate()); ps.setDate(16, domain.getPilotEndDate()); ps.setBoolean(17, domain.isFullSubscription()); ps.setObject(18, domain.getSubscriptionStartDate()); ps.setObject(19, domain.getSubscriptionEndDate()); ps.setLong(20, domain.getCreatorUserId()); ps.setTimestamp(21, domain.getCreationDate()); ps.setLong(22, domain.getModifierUserId()); ps.setTimestamp(23, domain.getModifiedDate()); } }); } catch (Exception e) { log.error("Error in inserting Domains", e); } }
From source file:org.atricore.idbus.idojos.dbsessionstore.DbSessionStore.java
protected void insert(Connection conn, BaseSession session) throws SQLException { final PreparedStatement ps = conn.prepareStatement(_insertDml); ps.setString(1, session.getId());//from w w w . j a v a 2 s.c o m ps.setString(2, session.getUsername()); ps.setLong(3, session.getCreationTime()); ps.setLong(4, session.getLastAccessTime()); ps.setInt(5, (int) session.getAccessCount()); ps.setInt(6, session.getMaxInactiveInterval()); ps.setBoolean(7, session.isValid()); ps.execute(); if (__log.isDebugEnabled()) __log.debug("Creation, LastAccess: " + session.getCreationTime() + ", " + session.getCreationTime()); if (__log.isDebugEnabled()) __log.debug("Session inserted: " + session.getId()); }
From source file:org.jboss.dashboard.dataset.sql.SQLStatement.java
/** * Get a JDBC prepared statement representing the SQL sentence. *//* w w w.j a v a2s . c om*/ public PreparedStatement getPreparedStatement(Connection connection) throws SQLException { PreparedStatement preparedStatement = connection.prepareStatement(SQLSentence); int psParamIndex = 1; Iterator paramIt = SQLParameters.iterator(); while (paramIt.hasNext()) { Object param = paramIt.next(); if (param instanceof String) preparedStatement.setString(psParamIndex, (String) param); else if (param instanceof Date) preparedStatement.setTimestamp(psParamIndex, new Timestamp(((Date) param).getTime())); else if (param instanceof Float) preparedStatement.setFloat(psParamIndex, ((Float) param).floatValue()); else if (param instanceof Double) preparedStatement.setDouble(psParamIndex, ((Double) param).doubleValue()); else if (param instanceof Number) preparedStatement.setLong(psParamIndex, ((Number) param).longValue()); else if (param instanceof Boolean) preparedStatement.setBoolean(psParamIndex, ((Boolean) param).booleanValue()); else if (param instanceof LabelInterval) preparedStatement.setString(psParamIndex, ((LabelInterval) param).getLabel()); psParamIndex++; } return preparedStatement; }
From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectOracle.java
@Override public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: String v;//from w w w .jav a 2 s . c om if (column.getType() == ColumnType.BLOBID) { v = ((Binary) value).getDigest(); } else { v = (String) value; } ps.setString(index, v); break; case Types.BIT: ps.setBoolean(index, ((Boolean) value).booleanValue()); return; case Types.TINYINT: case Types.SMALLINT: ps.setInt(index, ((Long) value).intValue()); return; case Types.INTEGER: case Types.BIGINT: ps.setLong(index, ((Long) value).longValue()); return; case Types.DOUBLE: ps.setDouble(index, ((Double) value).doubleValue()); return; case Types.TIMESTAMP: Calendar cal = (Calendar) value; Timestamp ts = new Timestamp(cal.getTimeInMillis()); ps.setTimestamp(index, ts, cal); // cal passed for timezone return; // case Types.OTHER: // if (column.getType() == Type.FTSTORED) { // ps.setString(index, (String) value); // return; // } // throw new SQLException("Unhandled type: " + column.getType()); default: throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); } }
From source file:com.wso2telco.gsma.authenticators.dao.impl.AttributeConfigDaoImpl.java
@Override public void saveUserConsentedAttributes(List<UserConsentHistory> userConsentHistory) throws NamingException, DBUtilException { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null;//from w w w. j a v a2 s . com String query = "INSERT INTO " + TableName.USER_CONSENT + "(consent_id,msisdn,expire_time,consent_status," + "client_id,operator) " + "VALUES (?,?,?,?,?,?);"; try { connection = getConnectDBConnection(); preparedStatement = connection.prepareStatement(query); for (UserConsentHistory userConsentHistory1 : userConsentHistory) { preparedStatement.setInt(1, userConsentHistory1.getConsentId()); preparedStatement.setString(2, userConsentHistory1.getMsisdn()); preparedStatement.setString(3, userConsentHistory1.getConsentExpireTime()); preparedStatement.setBoolean(4, Boolean.parseBoolean(userConsentHistory1.getConsentStatus())); preparedStatement.setString(5, userConsentHistory1.getClientId()); preparedStatement.setString(6, userConsentHistory1.getOperatorName()); preparedStatement.addBatch(); } if (log.isDebugEnabled()) { log.debug("Query in method saveUserConsentedAttributes:" + preparedStatement); } preparedStatement.executeBatch(); } catch (SQLException e) { log.error("Exception occurred while inserting data to the database for history : " + userConsentHistory.toString() + " :" + e.getMessage()); throw new DBUtilException(e.getMessage(), e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, resultSet, preparedStatement); } }
From source file:org.carlspring.tools.csv.dao.CSVDao.java
private void setField(PreparedStatement ps, int i, Field field, String value) throws SQLException { // Handle primitives if (field.getType().equals("int")) { ps.setInt(i, StringUtils.isBlank(value) ? 0 : Integer.parseInt(value)); } else if (field.getType().equals("long")) { ps.setLong(i, StringUtils.isBlank(value) ? 0l : Long.parseLong(value)); } else if (field.getType().equals("float")) { ps.setFloat(i, StringUtils.isBlank(value) ? 0f : Float.parseFloat(value)); } else if (field.getType().equals("double")) { ps.setDouble(i, StringUtils.isBlank(value) ? 0d : Double.parseDouble(value)); } else if (field.getType().equals("boolean")) { ps.setBoolean(i, StringUtils.isBlank(value) && Boolean.parseBoolean(value)); }/*from w w w . j a v a 2 s. c o m*/ // Handle objects else if (field.getType().equals("java.lang.String")) { ps.setString(i, StringUtils.isBlank(value) ? null : value); } else if (field.getType().equals("java.sql.Date")) { ps.setDate(i, StringUtils.isBlank(value) ? null : Date.valueOf(value)); } else if (field.getType().equals("java.sql.Timestamp")) { ps.setTimestamp(i, StringUtils.isBlank(value) ? null : Timestamp.valueOf(value)); } else if (field.getType().equals("java.math.BigDecimal")) { ps.setBigDecimal(i, StringUtils.isBlank(value) ? null : new BigDecimal(Long.parseLong(value))); } }
From source file:com.npstrandberg.simplemq.MessageQueueImp.java
public boolean send(MessageInput messageInput) { if (messageInput == null) { throw new NullPointerException("The messageInput cannot be 'null'"); }/*from ww w . j a va 2 s .c o m*/ byte[] b = null; if (messageInput.getObject() != null) { b = Utils.serialize(messageInput.getObject()); // Check if the byte array can fit in the 'object' column. // the 'object' column is a BIGINT and has the same max size as Integer.MAX_VALUE if (b.length > Integer.MAX_VALUE) { throw new IllegalArgumentException( "The Object is to large, it can only be " + Integer.MAX_VALUE + " bytes."); } } try { PreparedStatement ps; if (b != null) { ps = conn.prepareStatement("INSERT INTO message (body, time, read, object) VALUES(?, ?, ?, ?)"); ps.setBinaryStream(4, new ByteArrayInputStream(b), b.length); } else { ps = conn.prepareStatement("INSERT INTO message (body, time, read) VALUES(?, ?, ?)"); } ps.setString(1, messageInput.getBody()); ps.setLong(2, System.nanoTime()); ps.setBoolean(3, false); ps.executeUpdate(); ps.close(); return true; } catch (SQLException e) { logger.error(e); } return false; }
From source file:net.mindengine.oculus.frontend.service.test.JdbcTestDAO.java
@Override public long create(Test test) throws Exception { PreparedStatement ps = getConnection().prepareStatement( "insert into tests (name, description, project_id, author_id, date, mapping, group_id, content, automated) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"); ps.setString(1, test.getName());/*from w w w .j a v a2s .com*/ ps.setString(2, test.getDescription()); ps.setLong(3, test.getProjectId()); ps.setLong(4, test.getAuthorId()); ps.setTimestamp(5, new Timestamp(test.getDate().getTime())); ps.setString(6, test.getMapping()); ps.setLong(7, test.getGroupId()); ps.setString(8, test.getContent()); ps.setBoolean(9, test.getAutomated()); logger.info(ps); ps.executeUpdate(); ResultSet rs = ps.getGeneratedKeys(); Long testId = 0L; if (rs.next()) { testId = rs.getLong(1); } /* * Increasing the tests_count value for current project */ update("update projects set tests_count=tests_count+1 where id = :id", "id", test.getProjectId()); return testId; }
From source file:org.dspace.storage.rdbms.DatabaseManager.java
private static void loadParameters(PreparedStatement statement, Collection<ColumnInfo> columns, TableRow row) throws SQLException { int count = 0; for (ColumnInfo info : columns) { count++;/* www . ja v a 2s . c om*/ String column = info.getCanonicalizedName(); int jdbctype = info.getType(); if (row.isColumnNull(column)) { statement.setNull(count, jdbctype); } else { switch (jdbctype) { case Types.BIT: statement.setBoolean(count, row.getBooleanColumn(column)); break; case Types.INTEGER: if (isOracle) { statement.setLong(count, row.getLongColumn(column)); } else { statement.setInt(count, row.getIntColumn(column)); } break; case Types.NUMERIC: case Types.DECIMAL: statement.setLong(count, row.getLongColumn(column)); // FIXME should be BigDecimal if TableRow supported that break; case Types.BIGINT: statement.setLong(count, row.getLongColumn(column)); break; case Types.CLOB: if (isOracle) { // Support CLOBs in place of TEXT columns in Oracle statement.setString(count, row.getStringColumn(column)); } else { throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype); } break; case Types.VARCHAR: statement.setString(count, row.getStringColumn(column)); break; case Types.DATE: statement.setDate(count, new java.sql.Date(row.getDateColumn(column).getTime())); break; case Types.TIME: statement.setTime(count, new Time(row.getDateColumn(column).getTime())); break; case Types.TIMESTAMP: statement.setTimestamp(count, new Timestamp(row.getDateColumn(column).getTime())); break; default: throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype); } } } }