当前位置: 首页>>代码示例>>Java>>正文


Java PreparedStatement.getParameterMetaData方法代码示例

本文整理汇总了Java中java.sql.PreparedStatement.getParameterMetaData方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.getParameterMetaData方法的具体用法?Java PreparedStatement.getParameterMetaData怎么用?Java PreparedStatement.getParameterMetaData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.PreparedStatement的用法示例。


在下文中一共展示了PreparedStatement.getParameterMetaData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPrepareBindExecuteFetchVarbinary

import java.sql.PreparedStatement; //导入方法依赖的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

示例2: testInterfaceImplementation

import java.sql.PreparedStatement; //导入方法依赖的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

示例3: checkStatementExecuteQuery

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void checkStatementExecuteQuery(Connection connection,
    boolean prepare) throws SQLException {
  final String sql = "select * from (\n"
      + "  values (1, 'a'), (null, 'b'), (3, 'c')) as t (c1, c2)";
  final Statement statement;
  final ResultSet resultSet;
  final ParameterMetaData parameterMetaData;
  if (prepare) {
    final PreparedStatement ps = connection.prepareStatement(sql);
    statement = ps;
    parameterMetaData = ps.getParameterMetaData();
    resultSet = ps.executeQuery();
  } else {
    statement = connection.createStatement();
    parameterMetaData = null;
    resultSet = statement.executeQuery(sql);
  }
  if (parameterMetaData != null) {
    assertThat(parameterMetaData.getParameterCount(), equalTo(0));
  }
  final ResultSetMetaData metaData = resultSet.getMetaData();
  assertEquals(2, metaData.getColumnCount());
  assertEquals("C1", metaData.getColumnName(1));
  assertEquals("C2", metaData.getColumnName(2));
  assertTrue(resultSet.next());
  assertTrue(resultSet.next());
  assertTrue(resultSet.next());
  assertFalse(resultSet.next());
  resultSet.close();
  statement.close();
  connection.close();
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:33,代码来源:RemoteDriverMockTest.java

示例4: checkStatementExecute

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void checkStatementExecute(Connection connection,
    boolean prepare, int maxRowCount) throws SQLException {
  final String sql = "select * from (\n"
      + "  values (1, 'a'), (null, 'b'), (3, 'c')) as t (c1, c2)";
  final Statement statement;
  final ResultSet resultSet;
  final ParameterMetaData parameterMetaData;
  if (prepare) {
    final PreparedStatement ps = connection.prepareStatement(sql);
    statement = ps;
    ps.setMaxRows(maxRowCount);
    parameterMetaData = ps.getParameterMetaData();
    assertTrue(ps.execute());
    resultSet = ps.getResultSet();
  } else {
    statement = connection.createStatement();
    statement.setMaxRows(maxRowCount);
    parameterMetaData = null;
    assertTrue(statement.execute(sql));
    resultSet = statement.getResultSet();
  }
  if (parameterMetaData != null) {
    assertThat(parameterMetaData.getParameterCount(), equalTo(0));
  }
  final ResultSetMetaData metaData = resultSet.getMetaData();
  assertEquals(2, metaData.getColumnCount());
  assertEquals("C1", metaData.getColumnName(1));
  assertEquals("C2", metaData.getColumnName(2));
  for (int i = 0; i < maxRowCount || (maxRowCount == 0 && i < 3); i++) {
    assertTrue(resultSet.next());
  }
  assertFalse(resultSet.next());
  resultSet.close();
  statement.close();
  connection.close();
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:37,代码来源:RemoteDriverTest.java

示例5: checkPrepareBindExecuteFetchDate

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void checkPrepareBindExecuteFetchDate(Connection connection) throws Exception {
  final String sql0 =
      "select cast(? as varchar(20)) as c\n"
          + "from (values (1, 'a'))";
  final String sql1 = "select ? + interval '2' day as c from (values (1, 'a'))";

  final Date date = Date.valueOf("2015-04-08");
  final long time = date.getTime();

  PreparedStatement ps;
  ParameterMetaData parameterMetaData;
  ResultSet resultSet;

  ps = connection.prepareStatement(sql0);
  parameterMetaData = ps.getParameterMetaData();
  assertThat(parameterMetaData.getParameterCount(), equalTo(1));
  ps.setDate(1, date);
  resultSet = ps.executeQuery();
  assertThat(resultSet.next(), is(true));
  assertThat(resultSet.getString(1), is("2015-04-08"));

  ps.setTimestamp(1, new Timestamp(time));
  resultSet = ps.executeQuery();
  assertThat(resultSet.next(), is(true));
  assertThat(resultSet.getString(1), is("2015-04-08 00:00:00.0"));

  ps.setTime(1, new Time(time));
  resultSet = ps.executeQuery();
  assertThat(resultSet.next(), is(true));
  assertThat(resultSet.getString(1), is("00:00:00"));
  ps.close();

  ps = connection.prepareStatement(sql1);
  parameterMetaData = ps.getParameterMetaData();
  assertThat(parameterMetaData.getParameterCount(), equalTo(1));

  ps.setDate(1, date);
  resultSet = ps.executeQuery();
  assertTrue(resultSet.next());
  assertThat(resultSet.getDate(1),
      equalTo(new Date(time + TimeUnit.DAYS.toMillis(2))));
  assertThat(resultSet.getTimestamp(1),
      equalTo(new Timestamp(time + TimeUnit.DAYS.toMillis(2))));

  ps.setTimestamp(1, new Timestamp(time));
  resultSet = ps.executeQuery();
  assertTrue(resultSet.next());
  assertThat(resultSet.getTimestamp(1),
      equalTo(new Timestamp(time + TimeUnit.DAYS.toMillis(2))));
  assertThat(resultSet.getTimestamp(1),
      equalTo(new Timestamp(time + TimeUnit.DAYS.toMillis(2))));

  ps.setObject(1, new java.util.Date(time));
  resultSet = ps.executeQuery();
  assertTrue(resultSet.next());
  assertThat(resultSet.getDate(1),
      equalTo(new Date(time + TimeUnit.DAYS.toMillis(2))));
  assertThat(resultSet.getTimestamp(1),
      equalTo(new Timestamp(time + TimeUnit.DAYS.toMillis(2))));

  resultSet.close();
  ps.close();
  connection.close();
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:65,代码来源:RemoteDriverTest.java


注:本文中的java.sql.PreparedStatement.getParameterMetaData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。