use of java.sql.ParameterMetaData in project spanner-jdbc by olavloite.
the class CloudSpannerParameterMetaDataTest method testGetParameterClassName.
@Test
public void testGetParameterClassName() throws SQLException {
try (CloudSpannerPreparedStatement ps = createSelectStatement()) {
ParameterMetaData metadata = ps.getParameterMetaData();
assertEquals(Long.class.getName(), metadata.getParameterClassName(1));
assertNull(metadata.getParameterClassName(2));
}
try (CloudSpannerPreparedStatement ps = createInsertStatement()) {
ParameterMetaData metadata = ps.getParameterMetaData();
assertEquals(Long.class.getName(), metadata.getParameterClassName(1));
assertEquals(String.class.getName(), metadata.getParameterClassName(2));
assertEquals(String.class.getName(), metadata.getParameterClassName(3));
}
}
use of java.sql.ParameterMetaData in project dbeaver by dbeaver.
the class OracleExecutionPlan method explain.
public void explain() throws DBException {
String planQuery = getPlanQueryString();
try {
// Delete previous statement rows
// (actually there should be no statement with this id -
// but let's do it, just in case)
JDBCPreparedStatement dbStat = session.prepareStatement("DELETE FROM " + planTableName + " WHERE STATEMENT_ID=? ");
try {
dbStat.setString(1, planStmtId);
dbStat.execute();
} finally {
dbStat.close();
}
// Explain plan
dbStat = session.prepareStatement(planQuery);
try {
try {
// Bind parameters if any
ParameterMetaData parameterMetaData = dbStat.getParameterMetaData();
if (parameterMetaData != null && parameterMetaData.getParameterCount() > 0) {
for (int i = 0; i < parameterMetaData.getParameterCount(); i++) {
dbStat.setNull(i + 1, Types.VARCHAR);
}
}
} catch (Exception e) {
log.error(e);
}
dbStat.execute();
} finally {
dbStat.close();
}
// Read explained plan
dbStat = session.prepareStatement("SELECT * FROM " + planTableName + " WHERE STATEMENT_ID=? ORDER BY ID");
readPlanNodes(dbStat);
} catch (SQLException e) {
throw new DBCException(e, session.getExecutionContext());
}
}
use of java.sql.ParameterMetaData in project incubator-gobblin by apache.
the class TeradataBufferedInserter method getColumnPosSqlTypes.
/**
* Creates a mapping between column positions and their data types
* @return A map containing the position of the columns along with their data type as value
*/
private Map<Integer, Integer> getColumnPosSqlTypes() {
try {
final Map<Integer, Integer> columnPosSqlTypes = Maps.newHashMap();
ParameterMetaData pMetaData = this.insertPstmtForFixedBatch.getParameterMetaData();
for (int i = 1; i <= pMetaData.getParameterCount(); i++) {
columnPosSqlTypes.put(i, pMetaData.getParameterType(i));
}
return columnPosSqlTypes;
} catch (SQLException e) {
throw new RuntimeException("Cannot retrieve columns types for batch insert", e);
}
}
use of java.sql.ParameterMetaData in project phoenix by apache.
the class QueryMetaDataTest method testInListParameterMetaData2.
@Test
public void testInListParameterMetaData2() throws Exception {
String query = "SELECT a_string, b_string FROM atable WHERE ? IN (2.2, 3)";
Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
PreparedStatement statement = conn.prepareStatement(query);
ParameterMetaData pmd = statement.getParameterMetaData();
assertEquals(1, pmd.getParameterCount());
assertEquals(BigDecimal.class.getName(), pmd.getParameterClassName(1));
}
use of java.sql.ParameterMetaData in project phoenix by apache.
the class QueryMetaDataTest method testToDateFunctionMetaData.
@Test
public void testToDateFunctionMetaData() throws Exception {
String query = "SELECT a_string, b_string FROM atable WHERE a_date > to_date(?)";
Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
PreparedStatement statement = conn.prepareStatement(query);
ParameterMetaData pmd = statement.getParameterMetaData();
assertEquals(1, pmd.getParameterCount());
assertEquals(String.class.getName(), pmd.getParameterClassName(1));
}
Aggregations