本文整理匯總了Java中java.sql.ParameterMetaData.getParameterCount方法的典型用法代碼示例。如果您正苦於以下問題:Java ParameterMetaData.getParameterCount方法的具體用法?Java ParameterMetaData.getParameterCount怎麽用?Java ParameterMetaData.getParameterCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.ParameterMetaData
的用法示例。
在下文中一共展示了ParameterMetaData.getParameterCount方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parameters
import java.sql.ParameterMetaData; //導入方法依賴的package包/類
/**
* Converts from JDBC metadata to Avatica parameters
*/
protected static List<AvaticaParameter> parameters(ParameterMetaData metaData)
throws SQLException {
if (metaData == null) {
return Collections.emptyList();
}
final List<AvaticaParameter> params = new ArrayList<>();
for (int i = 1; i <= metaData.getParameterCount(); i++) {
params.add(
new AvaticaParameter(metaData.isSigned(i), metaData.getPrecision(i),
metaData.getScale(i), metaData.getParameterType(i),
metaData.getParameterTypeName(i),
metaData.getParameterClassName(i), "?" + i));
}
return params;
}
示例2: sendParameterDescription
import java.sql.ParameterMetaData; //導入方法依賴的package包/類
private void sendParameterDescription(Prepared p) throws IOException {
try {
PreparedStatement prep = p.prep;
ParameterMetaData meta = prep.getParameterMetaData();
int count = meta.getParameterCount();
startMessage('t');
writeShort(count);
for (int i = 0; i < count; i++) {
int type;
if (p.paramType != null && p.paramType[i] != 0) {
type = p.paramType[i];
} else {
type = PgServer.PG_TYPE_VARCHAR;
}
server.checkType(type);
writeInt(type);
}
sendMessage();
} catch (Exception e) {
sendErrorResponse(e);
}
}
示例3: assertStatementState
import java.sql.ParameterMetaData; //導入方法依賴的package包/類
private void assertStatementState(int[] parameterExpectedValues,
int[] expectedValues, Statement s)
throws SQLException {
assertEquals(expectedValues[0], s.getResultSetType());
assertEquals(
expectedValues[1], s.getResultSetConcurrency());
assertEquals(
expectedValues[2], s.getFetchDirection());
assertEquals(expectedValues[3], s.getFetchSize());
assertEquals(expectedValues[4], s.getMaxFieldSize());
assertEquals(expectedValues[5], s.getMaxRows());
assertEquals(expectedValues[6], s.getResultSetHoldability());
if (s instanceof PreparedStatement) {
PreparedStatement ps = (PreparedStatement) s;
ParameterMetaData psmd = ps.getParameterMetaData();
// Parameter count:
assertEquals(parameterExpectedValues[0], psmd.getParameterCount());
for (int i = 1; i <= psmd.getParameterCount(); i++) {
assertEquals(parameterExpectedValues[i], psmd.getParameterType(i));
}
}
}
示例4: testParameterMetaData
import java.sql.ParameterMetaData; //導入方法依賴的package包/類
/**
* tests parameterMetaData and reports error if the ParameterMetaData results
* does not match the expected results.
*
* @param paramMetaData ParameterMetadata object
* @param paramMetaDataArray 2 dimensional array containing expected test results.
* @exception SQLException if any error occurs
*/
static void testParameterMetaData(ParameterMetaData paramMetaData, String [][] paramMetaDataArray) throws SQLException {
int numParam = paramMetaData.getParameterCount();
for (int i=0, j=0; i<numParam; i++) {
assertEquals("Unexpected parameter isNullable", paramMetaDataArray[i][j++], parameterIsNullableInStringForm(paramMetaData.isNullable(i+1)));
assertEquals("Unexpected parameter isSigned", Boolean.valueOf(paramMetaDataArray[i][j++]).booleanValue(), paramMetaData.isSigned(i+1));
assertEquals("Unexpected parameter getPrecision", Integer.parseInt(paramMetaDataArray[i][j++]) , paramMetaData.getPrecision(i+1));
assertEquals("Unexpected parameter getScale", Integer.parseInt(paramMetaDataArray[i][j++]) , paramMetaData.getScale(i+1));
assertEquals("Unexpected parameter getParameterType", Integer.parseInt(paramMetaDataArray[i][j++]) , paramMetaData.getParameterType(i+1));
assertEquals("Unexpected parameter getParameterTypeName", paramMetaDataArray[i][j++] , paramMetaData.getParameterTypeName(i+1));
assertEquals("Unexpected parameter getParameterClassName", paramMetaDataArray[i][j++] , paramMetaData.getParameterClassName(i+1));
assertEquals("Unexpected parameter getParameterMode", paramMetaDataArray[i][j++] , parameterModeInStringForm(paramMetaData.getParameterMode(i+1)));
j=0;
}
}
示例5: getParameterResultSet
import java.sql.ParameterMetaData; //導入方法依賴的package包/類
private static String getParameterResultSet(ParameterMetaData meta)
throws SQLException {
StringBuilder buff = new StringBuilder();
if (meta == null) {
return "No parameter meta data";
}
buff.append("<table cellspacing=0 cellpadding=0>").
append("<tr><th>className</th><th>mode</th><th>type</th>").
append("<th>typeName</th><th>precision</th><th>scale</th></tr>");
for (int i = 0; i < meta.getParameterCount(); i++) {
buff.append("</tr><td>").
append(meta.getParameterClassName(i + 1)).
append("</td><td>").
append(meta.getParameterMode(i + 1)).
append("</td><td>").
append(meta.getParameterType(i + 1)).
append("</td><td>").
append(meta.getParameterTypeName(i + 1)).
append("</td><td>").
append(meta.getPrecision(i + 1)).
append("</td><td>").
append(meta.getScale(i + 1)).
append("</td></tr>");
}
buff.append("</table>");
return buff.toString();
}
示例6: testDataAwareProcedureWithoutResultSets
import java.sql.ParameterMetaData; //導入方法依賴的package包/類
public void testDataAwareProcedureWithoutResultSets()
throws Exception {
setup();
CallableStatement cs = prepareCall("CALL PROCEDURE_WITHOUT_RESULTSET(?, ?) ON TABLE EMP.PARTITIONTESTTABLE WHERE SECONDID=4 AND THIRDID='3'");
cs.registerOutParameter(2, java.sql.Types.VARCHAR, 20);
int number=2;
String name="INOUTPARAMETER";
cs.setInt(1, number);
cs.setString(2, name);
cs.execute();
ResultSet rs=cs.getResultSet();
if(rs!=null || cs.getMoreResults()) {
fail("no dynamic result set for the procedure!");
}
ParameterMetaData pmd=cs.getParameterMetaData();
int numParameters=pmd.getParameterCount();
assertTrue(" the number of parameter is 2", numParameters==2);
try {
cs.getInt(1);
fail("the in parameteter cannot be read!");
} catch (Exception e) {
}
Object parameter2=cs.getObject(2);
assertTrue("the second inout parameter is "+name+number, parameter2.equals(name+number));
}
示例7: testDataAwareProcedureWithoutResultSetsUsingGlobalIndex
import java.sql.ParameterMetaData; //導入方法依賴的package包/類
public void testDataAwareProcedureWithoutResultSetsUsingGlobalIndex()
throws Exception {
setup();
CallableStatement cs = prepareCall("CALL PROCEDURE_WITHOUT_RESULTSET(?, ?) ON TABLE EMP.PARTITIONTESTTABLE1 WHERE SECONDID=4 AND THIRDID='3'");
cs.registerOutParameter(2, java.sql.Types.VARCHAR, 20);
int number=2;
String name="INOUTPARAMETER";
cs.setInt(1, number);
cs.setString(2, name);
cs.execute();
ResultSet rs=cs.getResultSet();
if(rs!=null || cs.getMoreResults()) {
fail("no dynamic result set for the procedure!");
}
ParameterMetaData pmd=cs.getParameterMetaData();
int numParameters=pmd.getParameterCount();
assertTrue(" the number of parameter is 2", numParameters==2);
try {
cs.getInt(1);
fail("the in parameteter cannot be read!");
} catch (Exception e) {
}
Object parameter2=cs.getObject(2);
assertTrue("the second inout parameter is "+name+number, parameter2.equals(name+number));
}
示例8: testDataAwareProcedureWithoutResultSets
import java.sql.ParameterMetaData; //導入方法依賴的package包/類
public void testDataAwareProcedureWithoutResultSets()
throws SQLException {
setup();
CallableStatement cs = prepareCall("CALL PROCEDURE_WITHOUT_RESULTSET(?, ?) ON TABLE EMP.PARTITIONTESTTABLE WHERE SECONDID=4 AND THIRDID='3'");
cs.registerOutParameter(2, java.sql.Types.VARCHAR, 20);
int number=2;
String name="INOUTPARAMETER";
cs.setInt(1, number);
cs.setString(2, name);
cs.execute();
ResultSet rs=cs.getResultSet();
if(rs!=null || cs.getMoreResults()) {
fail("no dynamic result set for the procedure!");
}
ParameterMetaData pmd=cs.getParameterMetaData();
int numParameters=pmd.getParameterCount();
assertTrue(" the number of parameter is 2", numParameters==2);
try {
cs.getInt(1);
fail("the in parameteter cannot be read!");
} catch (Exception e) {
}
Object parameter2=cs.getObject(2);
assertTrue("the second inout parameter is "+name+number, parameter2.equals(name+number));
}
示例9: testDataAwareProcedureWithoutResultSetsUsingGlobalIndex
import java.sql.ParameterMetaData; //導入方法依賴的package包/類
public void testDataAwareProcedureWithoutResultSetsUsingGlobalIndex()
throws SQLException {
setup();
CallableStatement cs = prepareCall("CALL PROCEDURE_WITHOUT_RESULTSET(?, ?) ON TABLE EMP.PARTITIONTESTTABLE1 WHERE SECONDID=4 AND THIRDID='3'");
cs.registerOutParameter(2, java.sql.Types.VARCHAR, 20);
int number=2;
String name="INOUTPARAMETER";
cs.setInt(1, number);
cs.setString(2, name);
cs.execute();
ResultSet rs=cs.getResultSet();
if(rs!=null || cs.getMoreResults()) {
fail("no dynamic result set for the procedure!");
}
ParameterMetaData pmd=cs.getParameterMetaData();
int numParameters=pmd.getParameterCount();
assertTrue(" the number of parameter is 2", numParameters==2);
try {
cs.getInt(1);
fail("the in parameteter cannot be read!");
} catch (Exception e) {
}
Object parameter2=cs.getObject(2);
assertTrue("the second inout parameter is "+name+number, parameter2.equals(name+number));
}
示例10: setProcedure
import java.sql.ParameterMetaData; //導入方法依賴的package包/類
/**
* @param procedure The procedure to set.
* @param columns columns
* @exception Exception Description of Exception
*/
public void setProcedure(String procedure, ArrayList columns) throws Exception {
if (isconfigured) { return; }
if (poolConnectionHandler != null) {
con = poolConnectionHandler.getConnection();
if (!isConnected()) { throw new Exception(
"JDBCLogger::setProcedure(), Given connection isnt connected to database !"); }
}
this.procedure = procedure;
// prepare call
CallableStatement cStmt = this.createCallableStatement(columns.size());
JDBCLogColumn logcol;
ParameterMetaData pmd;
// 2.6.2005 jschmied
// ParameterMetaData is supported on different levels by Oracle
try {
// J2SDK 1.4+; limited support by Oracle drivers 10.x and 9.x
pmd = cStmt.getParameterMetaData();
num = pmd.getParameterCount();
if (num >= 1) {
// oracle 10.1.0.4 has some stubs in ParameterMetaData,
// try if a function throws a UnsupportedFeature exception
pmd.getParameterType(1);
pmd.getParameterTypeName(1);
pmd.isNullable(1);
}
} catch (Exception e) {
pmd = null;
num = columns.size();
}
logcols = new ArrayList(num);
for (int i = 1; i <= num; i++) {
logcol = new JDBCLogColumn();
JDBCColumnStorage col = (JDBCColumnStorage) columns.get(i - 1);
logcol.name = col.column.toUpperCase();
if (pmd == null) {
logcol.type = col.type;
logcol.sqlType = col.sqlType;
logcol.nullable = true; // assume true
} else {
logcol.type = pmd.getParameterTypeName(i);
logcol.sqlType = pmd.getParameterType(i);
logcol.nullable = (pmd.isNullable(i) == ParameterMetaData.parameterNullable);
}
logcol.isWritable = true;
logcols.add(logcol);
}
cStmt.close();
freeConnection();
isconfigured = true;
}
示例11: setupCallableStatementParams
import java.sql.ParameterMetaData; //導入方法依賴的package包/類
private void setupCallableStatementParams(CallableStatement cs) throws SQLException
{
ParameterMetaData pmeta = getParameterMetaData();
int numElems = pmeta.getParameterCount();
for ( int i = 0; i < numElems; i ++)
{
boolean outputFlag = false;
int parameterMode = pmeta.getParameterMode(i + 1);
int parameterType = pmeta.getParameterType(i + 1);
int parameterPrecision = pmeta.getPrecision(i + 1);
int parameterScale = pmeta.getScale(i + 1);
switch (parameterMode) {
case JDBC30Translation.PARAMETER_MODE_IN:
break;
case JDBC30Translation.PARAMETER_MODE_OUT:
case JDBC30Translation.PARAMETER_MODE_IN_OUT:
outputFlag = true;
break;
case JDBC30Translation.PARAMETER_MODE_UNKNOWN:
// It's only unknown if array
String objectType = pmeta.getParameterClassName(i+1);
parameterType =
getOutputParameterTypeFromClassName(objectType);
if (parameterType != NOT_OUTPUT_PARAM)
outputFlag = true;
}
if (outputFlag)
{
if (outputTypes == null) //not initialized yet, since previously none output
{
outputTypes = new int[numElems];
outputPrecision = new int [numElems];
outputScale = new int [numElems];
for (int j = 0; j < numElems; j++) {
outputTypes[j] = NOT_OUTPUT_PARAM; //default init value
outputPrecision[j] = NOT_OUTPUT_PARAM;
outputScale[j] = NOT_OUTPUT_PARAM;
}
}
// save the output type so we can register when we parse
// the SQLDTA
outputTypes[i] = parameterType;
outputPrecision[i] = parameterPrecision;
outputScale[i] = parameterScale;
}
}
}