List of usage examples for java.sql Types VARCHAR
int VARCHAR
To view the source code for java.sql Types VARCHAR.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARCHAR
.
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMSSql.CFCrmMSSqlTopDomainTable.java
public void createTopDomain(CFCrmAuthorization Authorization, CFCrmTopDomainBuff Buff) { final String S_ProcName = "createTopDomain"; ResultSet resultSet = null;// www .j a va2 s .c o m try { String ClassCode = Buff.getClassCode(); long TenantId = Buff.getRequiredTenantId(); String Description = Buff.getOptionalDescription(); long TldId = Buff.getRequiredTldId(); String Name = Buff.getRequiredName(); Connection cnx = schema.getCnx(); String sql = "exec sp_create_tdomdef ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtCreateByPKey.setString(argIdx++, ClassCode); stmtCreateByPKey.setLong(argIdx++, TenantId); if (Description != null) { stmtCreateByPKey.setString(argIdx++, Description); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtCreateByPKey.setLong(argIdx++, TldId); stmtCreateByPKey.setString(argIdx++, Name); stmtCreateByPKey.execute(); boolean moreResults = true; resultSet = null; while (resultSet == null) { try { moreResults = stmtCreateByPKey.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtCreateByPKey.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtCreateByPKey.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } if (resultSet.next()) { CFCrmTopDomainBuff createdBuff = unpackTopDomainResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredTenantId(createdBuff.getRequiredTenantId()); Buff.setRequiredId(createdBuff.getRequiredId()); Buff.setOptionalDescription(createdBuff.getOptionalDescription()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); Buff.setCreatedByUserId(createdBuff.getCreatedByUserId()); Buff.setCreatedAt(createdBuff.getCreatedAt()); Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId()); Buff.setUpdatedAt(createdBuff.getUpdatedAt()); Buff.setRequiredTldId(createdBuff.getRequiredTldId()); Buff.setRequiredName(createdBuff.getRequiredName()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmDb2LUW.CFCrmDb2LUWProjectBaseTable.java
public void createProjectBase(CFCrmAuthorization Authorization, CFCrmProjectBaseBuff Buff) { final String S_ProcName = "createProjectBase"; ResultSet resultSet = null;// ww w . j a v a2s. c o m try { String ClassCode = Buff.getClassCode(); long TenantId = Buff.getRequiredTenantId(); String Description = Buff.getOptionalDescription(); Connection cnx = schema.getCnx(); final String sql = "CALL sp_create_bprjdef( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " )"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtCreateByPKey.setString(argIdx++, ClassCode); stmtCreateByPKey.setLong(argIdx++, TenantId); if (Description != null) { stmtCreateByPKey.setString(argIdx++, Description); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } resultSet = stmtCreateByPKey.executeQuery(); if (resultSet.next()) { CFCrmProjectBaseBuff createdBuff = unpackProjectBaseResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredTenantId(createdBuff.getRequiredTenantId()); Buff.setRequiredId(createdBuff.getRequiredId()); Buff.setOptionalDescription(createdBuff.getOptionalDescription()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); Buff.setCreatedByUserId(createdBuff.getCreatedByUserId()); Buff.setCreatedAt(createdBuff.getCreatedAt()); Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId()); Buff.setUpdatedAt(createdBuff.getUpdatedAt()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:mx.edu.um.escuela.dao.MaestroDaoJdbc.java
@Override public Maestro crea(final Maestro maestro) { log.debug("Creando al maestro {}", maestro); KeyHolder keyHolder = new GeneratedKeyHolder(); getJdbcTemplate().update(new PreparedStatementCreator() { @Override//from w ww . j a v a2s.c om public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(CREAR_MAESTRO, new String[] { "id" }); ps.setString(1, maestro.getNomina()); ps.setString(2, maestro.getNombre()); ps.setString(3, maestro.getApellido()); if (maestro.getFechaNacimiento() != null) { ps.setDate(4, new java.sql.Date(maestro.getFechaNacimiento().getTime())); } else { ps.setNull(4, Types.DATE); } ps.setBoolean(5, maestro.getEsHombre()); if (maestro.getCorreo() != null) { ps.setString(6, maestro.getCorreo()); } else { ps.setNull(6, Types.VARCHAR); } return ps; } }, keyHolder); maestro.setId(keyHolder.getKey().longValue()); maestros.add(maestro); return maestro; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskMSSql.CFAsteriskMSSqlSecDeviceTable.java
public void createSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) { final String S_ProcName = "createSecDevice"; if ("SDEV".equals(Buff.getClassCode()) && (!schema.isSystemUser(Authorization))) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Permission denied -- only system user can modify SecDevice data"); }/*from w ww .j a v a2s . com*/ if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } try { Connection cnx = schema.getCnx(); UUID SecUserId = Buff.getRequiredSecUserId(); String DevName = Buff.getRequiredDevName(); String PubKey = Buff.getOptionalPubKey(); int Revision = 1; String sql = "INSERT INTO " + schema.getLowerDbSchemaName() + "..SecDev( " + "forcesynclock, " + "createdby, " + "createdat, " + "updatedby, " + "updatedat, " + "secuserid, " + "devname, " + "pubkey" + ", revision )" + "VALUES ( " + "0, " + " ?, " + " getdate(), " + " ?, " + " getdate(), " + "?" + ", " + "?" + ", " + "?" + ", " + "1 )"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setString(argIdx++, Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, SecUserId.toString()); stmtCreateByPKey.setString(argIdx++, DevName); if (PubKey != null) { stmtCreateByPKey.setString(argIdx++, PubKey); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } int rowsAffected = stmtCreateByPKey.executeUpdate(); if (rowsAffected != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by insert, not " + rowsAffected); } Buff.setRequiredRevision(Revision); String sqlAuditCreated = "INSERT INTO " + schema.getLowerDbSchemaName() + "..SecDev_h( auditclusterid, " + " auditsessionid, " + " auditstamp" + ", " + "secuserid" + ", " + "devname" + ", " + "pubkey" + ", " + " revision, " + " auditaction ) " + "SELECT ?, ?, sysdatetime()" + ", " + "sdev.secuserid" + ", " + "sdev.devname" + ", " + "sdev.pubkey" + ", " + " sdev.revision, " + " 1" + "FROM " + schema.getLowerDbSchemaName() + "..SecDev AS sdev " + " WHERE " + "sdev.secuserid = ? " + "AND sdev.devname = ? "; if (stmtAuditCreatedByPKey == null) { stmtAuditCreatedByPKey = cnx.prepareStatement(sqlAuditCreated); } argIdx = 1; stmtAuditCreatedByPKey.setLong(argIdx++, Authorization.getSecClusterId()); stmtAuditCreatedByPKey.setString(argIdx++, Authorization.getSecSessionId().toString()); stmtAuditCreatedByPKey.setString(argIdx++, SecUserId.toString()); stmtAuditCreatedByPKey.setString(argIdx++, DevName); int rowsAudited = stmtAuditCreatedByPKey.executeUpdate(); if (rowsAudited != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by audit via insert-selected, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMSSql.CFCrmMSSqlTopProjectTable.java
public void createTopProject(CFCrmAuthorization Authorization, CFCrmTopProjectBuff Buff) { final String S_ProcName = "createTopProject"; ResultSet resultSet = null;/*from w w w . j a v a 2 s. c om*/ try { String ClassCode = Buff.getClassCode(); long TenantId = Buff.getRequiredTenantId(); String Description = Buff.getOptionalDescription(); long DomainId = Buff.getRequiredDomainId(); String Name = Buff.getRequiredName(); Connection cnx = schema.getCnx(); String sql = "exec sp_create_tprjdef ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtCreateByPKey.setString(argIdx++, ClassCode); stmtCreateByPKey.setLong(argIdx++, TenantId); if (Description != null) { stmtCreateByPKey.setString(argIdx++, Description); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtCreateByPKey.setLong(argIdx++, DomainId); stmtCreateByPKey.setString(argIdx++, Name); stmtCreateByPKey.execute(); boolean moreResults = true; resultSet = null; while (resultSet == null) { try { moreResults = stmtCreateByPKey.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtCreateByPKey.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtCreateByPKey.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } if (resultSet.next()) { CFCrmTopProjectBuff createdBuff = unpackTopProjectResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredTenantId(createdBuff.getRequiredTenantId()); Buff.setRequiredId(createdBuff.getRequiredId()); Buff.setOptionalDescription(createdBuff.getOptionalDescription()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); Buff.setCreatedByUserId(createdBuff.getCreatedByUserId()); Buff.setCreatedAt(createdBuff.getCreatedAt()); Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId()); Buff.setUpdatedAt(createdBuff.getUpdatedAt()); Buff.setRequiredDomainId(createdBuff.getRequiredDomainId()); Buff.setRequiredName(createdBuff.getRequiredName()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:annis.test.CsvResultSetProvider.java
public CsvResultSetProvider(InputStream csvStream) throws SQLException { MockitoAnnotations.initMocks((CsvResultSetProvider) this); header = new HashMap<String, Integer>(); reader = new CSVReader(new InputStreamReader(csvStream), ';', '"'); try {/*from w ww . ja v a 2 s.com*/ String[] firstLine = reader.readNext(); for (int i = 0; firstLine != null && i < firstLine.length; i++) { header.put(firstLine[i], i); } } catch (IOException ex) { log.error(null, ex); } wasNull = false; // mock all needed methods of the ResultSet when(rs.next()).thenAnswer(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { try { current = reader.readNext(); return current != null && current.length > 0; } catch (IOException ex) { return false; } } }); when(rs.wasNull()).thenAnswer(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { return wasNull; } }); when(rs.findColumn(anyString())).thenAnswer(new Answer<Integer>() { @Override public Integer answer(InvocationOnMock invocation) throws Throwable { String arg = (String) invocation.getArguments()[0]; return getColumnByName(arg) + 1; } }); // getter with column position as argument when(rs.getString(anyInt())).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { int idx = (Integer) invocation.getArguments()[0]; return getStringValue(idx - 1); } }); when(rs.getLong(anyInt())).thenAnswer(new Answer<Long>() { @Override public Long answer(InvocationOnMock invocation) throws Throwable { int idx = (Integer) invocation.getArguments()[0]; return getLongValue(idx - 1); } }); when(rs.getInt(anyInt())).thenAnswer(new Answer<Integer>() { @Override public Integer answer(InvocationOnMock invocation) throws Throwable { int idx = (Integer) invocation.getArguments()[0]; return getIntValue(idx - 1); } }); when(rs.getBoolean(anyInt())).thenAnswer(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { int idx = (Integer) invocation.getArguments()[0]; return getBooleanValue(idx - 1); } }); when(rs.getArray(anyInt())).thenAnswer(new Answer<Array>() { @Override public Array answer(InvocationOnMock invocation) throws Throwable { int idx = (Integer) invocation.getArguments()[0]; return new DummySQLArray(getArrayValue(idx - 1, Types.VARCHAR), Types.VARCHAR, "VARCHAR"); } }); when(rs.getObject(anyInt())).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { int idx = (Integer) invocation.getArguments()[0]; return getObjectValue(idx - 1); } }); // getter with column name as argument when(rs.getString(anyString())).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { return getStringValue(getColumnByName((String) invocation.getArguments()[0])); } }); when(rs.getLong(anyString())).thenAnswer(new Answer<Long>() { @Override public Long answer(InvocationOnMock invocation) throws Throwable { return getLongValue(getColumnByName((String) invocation.getArguments()[0])); } }); when(rs.getInt(anyString())).thenAnswer(new Answer<Integer>() { @Override public Integer answer(InvocationOnMock invocation) throws Throwable { return getIntValue(getColumnByName((String) invocation.getArguments()[0])); } }); when(rs.getBoolean(anyString())).thenAnswer(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { return getBooleanValue(getColumnByName((String) invocation.getArguments()[0])); } }); when(rs.getArray(anyString())).thenAnswer(new Answer<Array>() { @Override public Array answer(InvocationOnMock invocation) throws Throwable { // HACK: we don't know how to get the type, use our knowledge if ("key".equalsIgnoreCase((String) invocation.getArguments()[0])) { return new DummySQLArray( getArrayValue(getColumnByName((String) invocation.getArguments()[0]), Types.BIGINT), Types.BIGINT, "BIGINT"); } else { return new DummySQLArray( getArrayValue(getColumnByName((String) invocation.getArguments()[0]), Types.VARCHAR), Types.VARCHAR, "VARCHAR"); } } }); when(rs.getObject(anyString())).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return getObjectValue(getColumnByName((String) invocation.getArguments()[0])); } }); }
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMSSql.CFCrmMSSqlMinorVersionTable.java
public void createMinorVersion(CFCrmAuthorization Authorization, CFCrmMinorVersionBuff Buff) { final String S_ProcName = "createMinorVersion"; ResultSet resultSet = null;/*from w ww . j a v a2s . c om*/ try { String ClassCode = Buff.getClassCode(); long TenantId = Buff.getRequiredTenantId(); String Description = Buff.getOptionalDescription(); long MajorId = Buff.getRequiredMajorId(); String Name = Buff.getRequiredName(); Connection cnx = schema.getCnx(); String sql = "exec sp_create_mnverdef ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtCreateByPKey.setString(argIdx++, ClassCode); stmtCreateByPKey.setLong(argIdx++, TenantId); if (Description != null) { stmtCreateByPKey.setString(argIdx++, Description); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtCreateByPKey.setLong(argIdx++, MajorId); stmtCreateByPKey.setString(argIdx++, Name); stmtCreateByPKey.execute(); boolean moreResults = true; resultSet = null; while (resultSet == null) { try { moreResults = stmtCreateByPKey.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtCreateByPKey.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtCreateByPKey.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } if (resultSet.next()) { CFCrmMinorVersionBuff createdBuff = unpackMinorVersionResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredTenantId(createdBuff.getRequiredTenantId()); Buff.setRequiredId(createdBuff.getRequiredId()); Buff.setOptionalDescription(createdBuff.getOptionalDescription()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); Buff.setCreatedByUserId(createdBuff.getCreatedByUserId()); Buff.setCreatedAt(createdBuff.getCreatedAt()); Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId()); Buff.setUpdatedAt(createdBuff.getUpdatedAt()); Buff.setRequiredMajorId(createdBuff.getRequiredMajorId()); Buff.setRequiredName(createdBuff.getRequiredName()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMSSql.CFCrmMSSqlSubProjectTable.java
public void createSubProject(CFCrmAuthorization Authorization, CFCrmSubProjectBuff Buff) { final String S_ProcName = "createSubProject"; ResultSet resultSet = null;//from ww w . ja v a 2s. c om try { String ClassCode = Buff.getClassCode(); long TenantId = Buff.getRequiredTenantId(); String Description = Buff.getOptionalDescription(); long ParentProjectId = Buff.getRequiredParentProjectId(); String Name = Buff.getRequiredName(); Connection cnx = schema.getCnx(); String sql = "exec sp_create_sprjdef ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtCreateByPKey.setString(argIdx++, ClassCode); stmtCreateByPKey.setLong(argIdx++, TenantId); if (Description != null) { stmtCreateByPKey.setString(argIdx++, Description); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtCreateByPKey.setLong(argIdx++, ParentProjectId); stmtCreateByPKey.setString(argIdx++, Name); stmtCreateByPKey.execute(); boolean moreResults = true; resultSet = null; while (resultSet == null) { try { moreResults = stmtCreateByPKey.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtCreateByPKey.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtCreateByPKey.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } if (resultSet.next()) { CFCrmSubProjectBuff createdBuff = unpackSubProjectResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredTenantId(createdBuff.getRequiredTenantId()); Buff.setRequiredId(createdBuff.getRequiredId()); Buff.setOptionalDescription(createdBuff.getOptionalDescription()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); Buff.setCreatedByUserId(createdBuff.getCreatedByUserId()); Buff.setCreatedAt(createdBuff.getCreatedAt()); Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId()); Buff.setUpdatedAt(createdBuff.getUpdatedAt()); Buff.setRequiredParentProjectId(createdBuff.getRequiredParentProjectId()); Buff.setRequiredName(createdBuff.getRequiredName()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMSSql.CFCrmMSSqlProjectBaseTable.java
public void createProjectBase(CFCrmAuthorization Authorization, CFCrmProjectBaseBuff Buff) { final String S_ProcName = "createProjectBase"; ResultSet resultSet = null;//from w w w.j a v a2 s.co m try { String ClassCode = Buff.getClassCode(); long TenantId = Buff.getRequiredTenantId(); String Description = Buff.getOptionalDescription(); Connection cnx = schema.getCnx(); String sql = "exec sp_create_bprjdef ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtCreateByPKey.setString(argIdx++, ClassCode); stmtCreateByPKey.setLong(argIdx++, TenantId); if (Description != null) { stmtCreateByPKey.setString(argIdx++, Description); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtCreateByPKey.execute(); boolean moreResults = true; resultSet = null; while (resultSet == null) { try { moreResults = stmtCreateByPKey.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtCreateByPKey.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtCreateByPKey.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } if (resultSet.next()) { CFCrmProjectBaseBuff createdBuff = unpackProjectBaseResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredTenantId(createdBuff.getRequiredTenantId()); Buff.setRequiredId(createdBuff.getRequiredId()); Buff.setOptionalDescription(createdBuff.getOptionalDescription()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); Buff.setCreatedByUserId(createdBuff.getCreatedByUserId()); Buff.setCreatedAt(createdBuff.getCreatedAt()); Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId()); Buff.setUpdatedAt(createdBuff.getUpdatedAt()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:com.streamsets.pipeline.stage.it.AllNullTypesIT.java
@Test public void testType() throws Exception { HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().build(); HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build(); Map<String, Field> map = new LinkedHashMap<>(); map.put("col", field); Record record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); try {/*from w ww.j a va 2s . c om*/ processRecords(processor, hiveTarget, ImmutableList.of(record)); if (!supported) { Assert.fail("Type is not supported, but yet no exception was thrown"); } } catch (StageException se) { if (supported) { LOG.error("Processing exception", se); Assert.fail("Processing testing record unexpectedly failed: " + se.getMessage()); throw se; } else { Assert.assertEquals(Errors.HIVE_19, se.getErrorCode()); // No additional verification necessary return; } } assertTableExists("default.tbl"); assertQueryResult("select * from tbl", new QueryValidator() { @Override public void validateResultSet(ResultSet rs) throws Exception { assertResultSetStructure(rs, new ImmutablePair("tbl.col", hiveType), new ImmutablePair("tbl.dt", Types.VARCHAR)); Assert.assertTrue("Table tbl doesn't contain any rows", rs.next()); Assert.assertEquals(null, rs.getObject(1)); Assert.assertFalse("Table tbl contains more then one row", rs.next()); } }); }