本文整理汇总了Java中java.sql.PreparedStatement.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.getConnection方法的具体用法?Java PreparedStatement.getConnection怎么用?Java PreparedStatement.getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.PreparedStatement
的用法示例。
在下文中一共展示了PreparedStatement.getConnection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setNonNullParameter
import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Object[] parameter,
JdbcType jdbcType) throws SQLException {
String typeName = null;
if (parameter instanceof Integer[]) {
typeName = TYPE_NAME_INTEGER;
} else if (parameter instanceof String[]) {
typeName = TYPE_NAME_VARCHAR;
} else if (parameter instanceof Boolean[]) {
typeName = TYPE_NAME_BOOLEAN;
} else if (parameter instanceof Double[]) {
typeName = TYPE_NAME_NUMERIC;
}
if (typeName == null) {
throw new TypeException("ArrayTypeHandler parameter typeName error, your type is " + parameter.getClass().getName());
}
// 这3行是关键的代码,创建Array,然后ps.setArray(i, array)就可以了
Connection conn = ps.getConnection();
Array array = conn.createArrayOf(typeName, parameter);
ps.setArray(i, array);
}
示例2: testPrepareStatement
import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Test
public void testPrepareStatement() throws SQLException
{
CloudSpannerPooledConnection subject = createConnection();
Connection connection = subject.getConnection();
PreparedStatement statement = connection.prepareStatement("SELECT COL1, COL2, COL3 FROM FOO");
assertFalse(statement.isClosed());
Connection statementConnection = statement.getConnection();
assertEquals(connection, statementConnection);
assertEquals(ResultSet.TYPE_FORWARD_ONLY, statement.getResultSetType());
try
{
statement.cancel();
}
catch (SQLException e)
{
}
statement.close();
assertTrue(statement.isClosed());
}
示例3: nullSafeSet
import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
Connection connection = st.getConnection();
if (value == null) {
st.setNull(index, sqlTypes()[0]);
} else {
@SuppressWarnings("unchecked") ArrayList<Long> castObject = (ArrayList) value;
Long[] longs = castObject.toArray(new Long[castObject.size()]);
Array array = connection.createArrayOf("bigint", longs);
st.setArray(index, array);
}
}
示例4: getOracleConnection
import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
* Retrieve the underlying OracleConnection, using a NativeJdbcExtractor if set.
*/
protected Connection getOracleConnection(PreparedStatement ps)
throws SQLException, ClassNotFoundException {
return (nativeJdbcExtractor != null ?
nativeJdbcExtractor.getNativeConnectionFromStatement(ps) : ps.getConnection());
}