本文整理匯總了Java中java.sql.PreparedStatement.setNull方法的典型用法代碼示例。如果您正苦於以下問題:Java PreparedStatement.setNull方法的具體用法?Java PreparedStatement.setNull怎麽用?Java PreparedStatement.setNull使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.PreparedStatement
的用法示例。
在下文中一共展示了PreparedStatement.setNull方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: transfer
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public boolean transfer(int nColumnNumber1Based, ResultSet resultSetSource, PreparedStatement insertStatementInsert)
{
try
{
Timestamp value = resultSetSource.getTimestamp(m_nColSourceIndex);
if (!resultSetSource.wasNull())
insertStatementInsert.setTimestamp(m_nColSourceIndex, value);
else
insertStatementInsert.setNull(m_nColSourceIndex, Types.TIMESTAMP);
return true;
}
catch (SQLException e)
{
e.printStackTrace();
}
return false;
}
示例2: setAppObject
import java.sql.PreparedStatement; //導入方法依賴的package包/類
/** Sets a parameter in the PreparedStatement.
* @param engineType The engine type as defined in init.xml
* @param pstmt The PreparedStatement.
* @param parameterIndex The index of the parameter that is to be set.
* @param value The object to be assigned to the parameter.
* @throws SQLException if a database access error occurs.
*/
public void setAppObject(PreparedStatement pstmt, int parameterIndex, Object value, String engineType)
throws SQLException {
if (value != null) {
if (!(value instanceof String))
value = DataTypeMapper.instance().map(value, String.class);
if ("oracle".equalsIgnoreCase(engineType) && !supportsStdLob(pstmt)) {
Clob clob = createClob(pstmt.getConnection(), (String) value);
pstmt.setClob(parameterIndex, clob);
} else {
String str = (String) value;
Reader reader = new BufferedReader(new StringReader(str));
pstmt.setCharacterStream(parameterIndex, reader, str.length());
}
} else
pstmt.setNull(parameterIndex, getSqlType(Defaults.CLOB, engineType));
}
示例3: set
import java.sql.PreparedStatement; //導入方法依賴的package包/類
protected void set(PreparedStatement st, Object value, int index, SessionImplementor session) throws SQLException {
if ( value == null ) {
st.setNull( index, sqlTypes( null )[0] );
}
else {
byte[] toSet = unWrap( value );
final boolean useInputStream = session.getFactory().getDialect().useInputStreamToInsertBlob();
if ( useInputStream ) {
st.setBinaryStream( index, new ByteArrayInputStream( toSet ), toSet.length );
}
else {
st.setBlob( index, Hibernate.getLobCreator( session ).createBlob( toSet ) );
}
}
}
示例4: transfer
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public boolean transfer(int nColumnNumber1Based, ResultSet resultSetSource, PreparedStatement insertStatementInsert)
{
try
{
String csValue = resultSetSource.getString(m_nColSourceIndex);
if (!resultSetSource.wasNull())
insertStatementInsert.setString(m_nColSourceIndex, csValue);
else
insertStatementInsert.setNull(m_nColSourceIndex, Types.VARCHAR);
return true;
}
catch (SQLException e)
{
e.printStackTrace();
}
return false;
}
示例5: transfer
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public boolean transfer(int nColumnNumber1Based, ResultSet resultSetSource, PreparedStatement insertStatementInsert)
{
try
{
long lValue = resultSetSource.getInt(m_nColSourceIndex);
if (!resultSetSource.wasNull())
insertStatementInsert.setLong(m_nColSourceIndex, lValue);
else
insertStatementInsert.setNull(m_nColSourceIndex, Types.INTEGER);
return true;
}
catch (SQLException e)
{
e.printStackTrace();
}
return false;
}
示例6: transfer
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public boolean transfer(int nColumnNumber1Based, ResultSet resultSetSource, PreparedStatement insertStatementInsert)
{
try
{
BigDecimal value = resultSetSource.getBigDecimal(m_nColSourceIndex);
if (!resultSetSource.wasNull())
insertStatementInsert.setBigDecimal(m_nColSourceIndex, value);
else
insertStatementInsert.setNull(m_nColSourceIndex, Types.DECIMAL);
return true;
}
catch (SQLException e)
{
e.printStackTrace();
}
return false;
}
示例7: setParameters
import java.sql.PreparedStatement; //導入方法依賴的package包/類
@Override
protected void setParameters(PreparedStatement p) throws SQLException {
long queryUserKey = 0;
try {
queryUserKey = Long.parseLong(userKey);
p.setLong(1, queryUserKey);
} catch (NumberFormatException e) {
p.setNull(1, Types.BIGINT);
}
}
示例8: createOrder
import java.sql.PreparedStatement; //導入方法依賴的package包/類
private OrderDataBean createOrder(Connection conn,
AccountDataBean accountData, QuoteDataBean quoteData,
HoldingDataBean holdingData, String orderType, double quantity)
throws Exception {
OrderDataBean orderData = null;
Timestamp currentDate = new Timestamp(System.currentTimeMillis());
PreparedStatement stmt = getStatement(conn, createOrderSQL);
Integer orderID = KeySequenceDirect.getNextID(conn, "order", inSession,
getInGlobalTxn());
stmt.setInt(1, orderID.intValue());
stmt.setString(2, orderType);
stmt.setString(3, "open");
stmt.setTimestamp(4, currentDate);
stmt.setDouble(5, quantity);
stmt.setBigDecimal(6, quoteData.getPrice().setScale(
FinancialUtils.SCALE, FinancialUtils.ROUND));
stmt.setBigDecimal(7, TradeConfig.getOrderFee(orderType));
stmt.setInt(8, accountData.getAccountID().intValue());
if (holdingData == null)
stmt.setNull(9, java.sql.Types.INTEGER);
else
stmt.setInt(9, holdingData.getHoldingID().intValue());
stmt.setString(10, quoteData.getSymbol());
int rowCount = stmt.executeUpdate();
stmt.close();
return getOrderData(conn, orderID.intValue());
}
示例9: setParams
import java.sql.PreparedStatement; //導入方法依賴的package包/類
/**
* 循環設置PreparedStatement的參數.
* @param pstmt PreparedStatement實例
* @param params 數組參數
* @return PreparedStatement實例
* @throws SQLException SQL異常
*/
private static PreparedStatement setParams(PreparedStatement pstmt, Object[] params) throws SQLException {
for (int i = 0, len = params.length; i < len; i++) {
Object param = params[i];
if (param != null) {
pstmt.setObject(i + 1, param);
} else {
pstmt.setNull(i + 1, Types.VARCHAR);
}
}
return pstmt;
}
示例10: testAny
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public void testAny() {
try {
String ddl =
"drop table PRICE_RELATE_USER_ORDER_V2 if exists;"
+ "create table PRICE_RELATE_USER_ORDER_V2 "
+ "(ID_ORDER_V2 BIGINT, ID_USER NUMERIC, DATE_CREATE TIMESTAMP)";
String sql = "insert into PRICE_RELATE_USER_ORDER_V2 "
+ "(ID_ORDER_V2, ID_USER, DATE_CREATE) " + "values "
+ "(?, ?, ?)";
Statement st = connection.createStatement();
st.execute(ddl);
PreparedStatement ps = connection.prepareStatement(sql);
ps.setLong(1, 1);
ps.setNull(2, Types.NUMERIC);
ps.setTimestamp(
3, new java.sql.Timestamp(System.currentTimeMillis()));
ps.execute();
} catch (SQLException e) {
e.printStackTrace();
System.out.println("TestSql.testAny() error: " + e.getMessage());
}
System.out.println("testAny complete");
}
示例11: writeBigDecimal
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static void writeBigDecimal(BigDecimal val, int paramIdx,
int sqlType, PreparedStatement s) throws SQLException {
if (null == val) {
s.setNull(paramIdx, sqlType);
} else {
s.setBigDecimal(paramIdx, val);
}
}
示例12: insertValuesIntoStatement
import java.sql.PreparedStatement; //導入方法依賴的package包/類
@Override
public PreparedStatement insertValuesIntoStatement(PreparedStatement statement, String[] values, String[] valueTypes, int offset) throws NumberFormatException, SQLException {
for (int i = 0; i < values.length; i++) {
String valueType = valueTypes[i + offset].toLowerCase();
if ((values[i] == null) || (values[i].equals(""))) {
if (valueType.contains("long") || valueType.contains("big") || valueType.contains("int8"))
statement.setNull(i + 1, java.sql.Types.BIGINT);
else if (valueType.contains("int") || valueType.contains("serial"))
statement.setNull(i + 1, java.sql.Types.INTEGER);
else if (valueType.contains("float") || valueType.contains("numeric") || valueType.contains("decimal") || valueType.contains("real") || valueType.contains("precision"))
statement.setNull(i + 1, java.sql.Types.FLOAT);
else if (valueType.contains("bool"))
statement.setNull(i + 1, java.sql.Types.BOOLEAN);
else if (valueType.contains("date"))
statement.setNull(i + 1, java.sql.Types.DATE);
else
statement.setNull(i + 1, java.sql.Types.VARCHAR);
}
else {
if (valueType.contains("long") || valueType.contains("big") || valueType.contains("int8"))
statement.setLong(i + 1, Long.valueOf(values[i]).longValue());
else if (valueType.contains("int") || valueType.contains("serial"))
statement.setInt(i + 1, Integer.valueOf(values[i]).intValue());
else if (valueType.contains("float") || valueType.contains("numeric") || valueType.contains("decimal") || valueType.contains("real") || valueType.contains("precision"))
statement.setFloat(i + 1, Float.valueOf(values[i]).shortValue());
else if (valueType.contains("bool"))
statement.setBoolean(i + 1, Boolean.valueOf(values[i]).booleanValue());
else if (valueType.contains("date"))
statement.setDate(i + 1, Date.valueOf(values[i]));
else
statement.setString(i + 1, values[i]);
}
}
return statement;
}
示例13: apply
import java.sql.PreparedStatement; //導入方法依賴的package包/類
@Override()
void apply(PreparedStatement stmt, int stmtIndex, DataFrameRow<R,C> row) {
try {
this.cursor.atRowOrdinal(row.ordinal());
if (cursor.isNull()) {
stmt.setNull(stmtIndex, colType.getTypeCode());
} else {
switch (colType) {
case BIT: stmt.setBoolean(stmtIndex, mapper.applyAsBoolean(cursor)); break;
case BOOLEAN: stmt.setBoolean(stmtIndex, mapper.applyAsBoolean(cursor)); break;
case TINYINT: stmt.setInt(stmtIndex, mapper.applyAsInt(cursor)); break;
case SMALLINT: stmt.setInt(stmtIndex, mapper.applyAsInt(cursor)); break;
case FLOAT: stmt.setDouble(stmtIndex, mapper.applyAsDouble(cursor)); break;
case INTEGER: stmt.setInt(stmtIndex, mapper.applyAsInt(cursor)); break;
case BIGINT: stmt.setLong(stmtIndex, mapper.applyAsLong(cursor)); break;
case DOUBLE: stmt.setDouble(stmtIndex, mapper.applyAsDouble(cursor)); break;
case DECIMAL: stmt.setDouble(stmtIndex, mapper.applyAsDouble(cursor)); break;
case VARCHAR: stmt.setString(stmtIndex, (String)mapper.apply(cursor)); break;
case DATE: stmt.setDate(stmtIndex, (Date)mapper.apply(cursor)); break;
case TIME: stmt.setTime(stmtIndex, (Time)mapper.apply(cursor)); break;
case DATETIME: stmt.setTimestamp(stmtIndex, (Timestamp)mapper.apply(cursor)); break;
default: throw new IllegalStateException("Unsupported column type:" + colType);
}
}
} catch (Exception ex) {
final String coordinates = String.format("(%s, %s)", cursor.rowKey(), cursor.colKey());
throw new DataFrameException("Failed to apply value to SQL statement at " + coordinates, ex);
}
}
示例14: writeDate
import java.sql.PreparedStatement; //導入方法依賴的package包/類
public static void writeDate(Date val, int paramIdx, int sqlType,
PreparedStatement s) throws SQLException {
if (null == val) {
s.setNull(paramIdx, sqlType);
} else {
s.setDate(paramIdx, val);
}
}
示例15: nullSafeSet
import java.sql.PreparedStatement; //導入方法依賴的package包/類
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index) throws SQLException
{
if( value != null )
{
String string = xstream.serialiseToXml(value);
StringReader reader = new StringReader(string);
st.setCharacterStream(index, reader, string.length());
}
else
{
st.setNull(index, sqlTypes()[0]);
}
}