當前位置: 首頁>>代碼示例>>Java>>正文


Java ParameterMetaData類代碼示例

本文整理匯總了Java中java.sql.ParameterMetaData的典型用法代碼示例。如果您正苦於以下問題:Java ParameterMetaData類的具體用法?Java ParameterMetaData怎麽用?Java ParameterMetaData使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ParameterMetaData類屬於java.sql包,在下文中一共展示了ParameterMetaData類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getParameterMetadata

import java.sql.ParameterMetaData; //導入依賴的package包/類
@Override
public IParameterMetaData getParameterMetadata(String query, List<Object> params) throws OdaException
{
	MetadataBean bean = new MetadataBean();
	int paramcount = 1;
	String[] queryStrings = getQueryStrings(query, null);
	for( String queryString : queryStrings )
	{
		int sz = queryString.length();
		for( int i = 0; i < sz; i++ )
		{
			char c = queryString.charAt(i);
			if( c == '?' )
			{
				Definition definition = addColumn("param" + (paramcount++), TYPE_STRING, bean); //$NON-NLS-1$
				definition.setMode(ParameterMetaData.parameterModeIn);
			}
		}
	}
	return bean;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:22,代碼來源:SimpleTypeQuery.java

示例2: 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;
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:19,代碼來源:JdbcMeta.java

示例3: testPrepareBindExecuteFetchVarbinary

import java.sql.ParameterMetaData; //導入依賴的package包/類
@Test public void testPrepareBindExecuteFetchVarbinary() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try {
    final Connection connection = getLocalConnection();
    final String sql = "select x'de' || ? as c from (values (1, 'a'))";
    final PreparedStatement ps =
        connection.prepareStatement(sql);
    final ParameterMetaData parameterMetaData = ps.getParameterMetaData();
    assertThat(parameterMetaData.getParameterCount(), equalTo(1));

    ps.setBytes(1, new byte[]{65, 0, 66});
    final ResultSet resultSet = ps.executeQuery();
    assertTrue(resultSet.next());
    assertThat(resultSet.getBytes(1),
        equalTo(new byte[]{(byte) 0xDE, 65, 0, 66}));
    resultSet.close();
    ps.close();
    connection.close();
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:23,代碼來源:RemoteDriverTest.java

示例4: getParameterMetaData

import java.sql.ParameterMetaData; //導入依賴的package包/類
/**
 * Get the parameter meta data of this prepared statement.
 *
 * @return the meta data
 */
@Override
public ParameterMetaData getParameterMetaData() throws SQLException {
    try {
        int id = getNextId(TraceObject.PARAMETER_META_DATA);
        if (isDebugEnabled()) {
            debugCodeAssign("ParameterMetaData",
                    TraceObject.PARAMETER_META_DATA, id, "getParameterMetaData()");
        }
        checkClosed();
        JdbcParameterMetaData meta = new JdbcParameterMetaData(
                session.getTrace(), this, command, id);
        return meta;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
 
開發者ID:vdr007,項目名稱:ThriftyPaxos,代碼行數:22,代碼來源:JdbcPreparedStatement.java

示例5: 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);
    }
}
 
開發者ID:vdr007,項目名稱:ThriftyPaxos,代碼行數:23,代碼來源:PgServerThread.java

示例6: testSetParameterValueWithNullAndGetParameterTypeWorkingButNotForOtherDriver

import java.sql.ParameterMetaData; //導入依賴的package包/類
@Test
public void testSetParameterValueWithNullAndGetParameterTypeWorkingButNotForOtherDriver() throws SQLException {
	StatementCreatorUtils.driversWithNoSupportForGetParameterType.clear();
	StatementCreatorUtils.driversWithNoSupportForGetParameterType.add("Oracle JDBC Driver");
	Connection con = mock(Connection.class);
	DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
	ParameterMetaData pmd = mock(ParameterMetaData.class);
	given(preparedStatement.getConnection()).willReturn(con);
	given(con.getMetaData()).willReturn(dbmd);
	given(dbmd.getDriverName()).willReturn("Apache Derby Embedded Driver");
	given(preparedStatement.getParameterMetaData()).willReturn(pmd);
	given(pmd.getParameterType(1)).willReturn(Types.SMALLINT);
	StatementCreatorUtils.setParameterValue(preparedStatement, 1, SqlTypeValue.TYPE_UNKNOWN, null, null);
	verify(dbmd).getDriverName();
	verify(pmd).getParameterType(1);
	verify(preparedStatement).setNull(1, Types.SMALLINT);
	assertEquals(1, StatementCreatorUtils.driversWithNoSupportForGetParameterType.size());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:StatementCreatorUtilsTests.java

示例7: testExecuteStatementUsing

import java.sql.ParameterMetaData; //導入依賴的package包/類
/** 
         * test execute statements that no parameters would be returned if 
         * prepareStatement("execute statement systab using values('SYS%','8000001%')");
  *
  * @exception SQLException if error occurs
         */

public void testExecuteStatementUsing () throws SQLException {

	/*
	 * the test no longer tests 4552, but kept as an interesting test scenario
                * bug 4552 - no parameters would be returned for execute statement using
                * System.out.println("Bug 4552 - no parameters would be returned for execute statement using");
                * orig: ps = con.prepareStatement("execute statement systab using values('SYS%','8000001%')");
	 */
     		PreparedStatement ps = prepareStatement("select * from sys.systables " + 
						"where CAST(tablename AS VARCHAR(128)) like 'SYS%' and " + 
						"CAST(tableID AS VARCHAR(128)) like '8000001%'");

     		ParameterMetaData paramMetaData = ps.getParameterMetaData();
	assertEquals("Unexpected parameter count", 0, paramMetaData.getParameterCount());

	//expected values to be stored in a 2dim. array
               String parameterMetaDataArray0 [][] = null;

               testParameterMetaData(paramMetaData, parameterMetaDataArray0);

     		ps.execute();

	ps.close();
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:32,代碼來源:ParameterMetaDataJdbc30Test.java

示例8: 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;
	}
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:25,代碼來源:ParameterMetaDataJdbc30Test.java

示例9: assertEquals

import java.sql.ParameterMetaData; //導入依賴的package包/類
/**
 * Check the ParameterMetaData for a statement whose first parameter is a UDT.
 */
private void checkPMD
    (
     Connection conn,
     String query,
     String expectedClassName,
     int expectedJDBCType,
     String expectedSQLTypeName,
     int expectedPrecision,
     int expectedScale
     ) throws Exception
{
    PreparedStatement ps = conn.prepareStatement( query );
    ParameterMetaData pmd = ps.getParameterMetaData();

    assertEquals( pmd.getParameterClassName( 1 ), expectedClassName );
    assertEquals( pmd.getParameterType( 1 ), expectedJDBCType );
    assertEquals( pmd.getParameterTypeName( 1 ), expectedSQLTypeName );
    assertEquals( pmd.getPrecision( 1 ), expectedPrecision );
    assertEquals( pmd.getScale( 1 ), expectedScale );

    ps.close();
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:26,代碼來源:UDTTest.java

示例10: testDynamicArgsMetaData

import java.sql.ParameterMetaData; //導入依賴的package包/類
/**
 * Test dynamic arguments
 */
public void testDynamicArgsMetaData() throws SQLException {

	//since there is no getParameterMetaData() call available in JSR169 
	//implementations, do not run this test if we are running JSR169
	if (JDBC.vmSupportsJSR169()) return;

    PreparedStatement ps = prepareStatement(
        "select * from t1 where a = ? order by b " +
        "offset ? rows fetch next ? rows only");

    ParameterMetaData pmd = ps.getParameterMetaData();
    int[] expectedTypes = { Types.INTEGER, Types.BIGINT, Types.BIGINT };

    for (int i = 0; i < 3; i++) {
        assertEquals("Unexpected parameter type",
                     expectedTypes[i], pmd.getParameterType(i+1));
        assertEquals("Derby ? args are nullable",
                     // Why is that? Cf. logic in ParameterNode.setType
                     ParameterMetaData.parameterNullable,
                     pmd.isNullable(i+1));
    }
    ps.close();
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:27,代碼來源:OffsetFetchNextTest.java

示例11: writeSQLDOPTGRP

import java.sql.ParameterMetaData; //導入依賴的package包/類
private void writeSQLDOPTGRP(ResultSetMetaData rsmeta,
							 ParameterMetaData pmeta,
							 int jdbcElemNum, boolean rtnOutput)
	throws DRDAProtocolException,SQLException
{

	writer.writeByte(0);
	//SQLUNAMED
	writer.writeShort(0);
	//SQLName
	writeVCMorVCS(rtnOutput ? rsmeta.getColumnName(jdbcElemNum) : null);
	//SQLLabel
	writeVCMorVCS(null);
	//SQLComments
	writeVCMorVCS(null);
	//SQLDUDTGRP 
	writeSQLUDTGRP(rsmeta, pmeta, jdbcElemNum, rtnOutput);
	//SQLDXGRP
	writeSQLDXGRP(rsmeta, pmeta, jdbcElemNum, rtnOutput);
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:21,代碼來源:DRDAConnThread.java

示例12: setParameter

import java.sql.ParameterMetaData; //導入依賴的package包/類
/**
 * statementにパラメータを設定します。
 * @param st ステートメント。
 * @param param パラメータ。
 * @throws Exception 例外。
 */
public void setParameter(final PreparedStatement st, final  Map<String, Object> param) throws Exception {
	if (this.paramnames != null && param != null) {
		int idx = 1;
		ParameterMetaData meta = getParameterMetaData(st);
		for (String p : this.paramnames) {
			Object v = this.getParam(p, param);
			if (log.isDebugEnabled()) {
				log.debug(idx + " :" + p + "=" + v);
			}
			if (v == null) {
				st.setNull(idx, this.getParameterType(meta, idx));
			} else {
				if (v instanceof FileObject) {
					log.debug("valueClass=" + v.getClass().getName());
					this.setBlobData(st, idx, (FileObject) v, meta);
				} else {
					st.setObject(idx, v);
				}
			}
			idx++;
		}
	}
}
 
開發者ID:takayanagi2087,項目名稱:dataforms,代碼行數:30,代碼來源:SqlParser.java

示例13: testInterfaceImplementation

import java.sql.ParameterMetaData; //導入依賴的package包/類
private void testInterfaceImplementation(Connection connToCheck) throws Exception {
    Method[] dbmdMethods = java.sql.DatabaseMetaData.class.getMethods();

    // can't do this statically, as we return different
    // implementations depending on JDBC version
    DatabaseMetaData dbmd = connToCheck.getMetaData();

    checkInterfaceImplemented(dbmdMethods, dbmd.getClass(), dbmd);

    Statement stmtToCheck = connToCheck.createStatement();

    checkInterfaceImplemented(java.sql.Statement.class.getMethods(), stmtToCheck.getClass(), stmtToCheck);

    PreparedStatement pStmtToCheck = connToCheck.prepareStatement("SELECT 1");
    ParameterMetaData paramMd = pStmtToCheck.getParameterMetaData();

    checkInterfaceImplemented(java.sql.PreparedStatement.class.getMethods(), pStmtToCheck.getClass(), pStmtToCheck);
    checkInterfaceImplemented(java.sql.ParameterMetaData.class.getMethods(), paramMd.getClass(), paramMd);

    pStmtToCheck = ((com.mysql.jdbc.Connection) connToCheck).serverPrepareStatement("SELECT 1");

    checkInterfaceImplemented(java.sql.PreparedStatement.class.getMethods(), pStmtToCheck.getClass(), pStmtToCheck);
    ResultSet toCheckRs = connToCheck.createStatement().executeQuery("SELECT 1");
    checkInterfaceImplemented(java.sql.ResultSet.class.getMethods(), toCheckRs.getClass(), toCheckRs);
    toCheckRs = connToCheck.createStatement().executeQuery("SELECT 1");
    checkInterfaceImplemented(java.sql.ResultSetMetaData.class.getMethods(), toCheckRs.getMetaData().getClass(), toCheckRs.getMetaData());

    if (versionMeetsMinimum(5, 0, 0)) {
        createProcedure("interfaceImpl", "(IN p1 INT)\nBEGIN\nSELECT 1;\nEND");

        CallableStatement cstmt = connToCheck.prepareCall("{CALL interfaceImpl(?)}");

        checkInterfaceImplemented(java.sql.CallableStatement.class.getMethods(), cstmt.getClass(), cstmt);
    }
    checkInterfaceImplemented(java.sql.Connection.class.getMethods(), connToCheck.getClass(), connToCheck);
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:37,代碼來源:ConnectionTest.java

示例14: getParameterMetaData

import java.sql.ParameterMetaData; //導入依賴的package包/類
/**
 * @see java.sql.PreparedStatement#getParameterMetaData()
 */
@Override
public ParameterMetaData getParameterMetaData() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {

        if (this.parameterMetaData == null) {
            this.parameterMetaData = new MysqlParameterMetadata(this.parameterFields, this.parameterCount, getExceptionInterceptor());
        }

        return this.parameterMetaData;
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:15,代碼來源:ServerPreparedStatement.java

示例15: getParameterMetaData

import java.sql.ParameterMetaData; //導入依賴的package包/類
@Override
public ParameterMetaData getParameterMetaData() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (this.placeholderToParameterIndexMap == null) {
            return this.paramInfo;
        }

        return new CallableStatementParamInfo(this.paramInfo);
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:11,代碼來源:CallableStatement.java


注:本文中的java.sql.ParameterMetaData類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。