Search in sources :

Example 66 with ParameterMetaData

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));
    }
}
Also used : ParameterMetaData(java.sql.ParameterMetaData) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 67 with ParameterMetaData

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());
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) SQLException(java.sql.SQLException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) ParameterMetaData(java.sql.ParameterMetaData) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) DBException(org.jkiss.dbeaver.DBException)

Example 68 with ParameterMetaData

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);
    }
}
Also used : SQLException(java.sql.SQLException) ParameterMetaData(java.sql.ParameterMetaData)

Example 69 with ParameterMetaData

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));
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) ParameterMetaData(java.sql.ParameterMetaData) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 70 with ParameterMetaData

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));
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) ParameterMetaData(java.sql.ParameterMetaData) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Aggregations

ParameterMetaData (java.sql.ParameterMetaData)136 PreparedStatement (java.sql.PreparedStatement)82 Test (org.junit.Test)55 Connection (java.sql.Connection)45 SQLException (java.sql.SQLException)35 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)31 ResultSet (java.sql.ResultSet)22 Statement (java.sql.Statement)20 ResultSetMetaData (java.sql.ResultSetMetaData)18 SQLServerParameterMetaData (com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData)15 BigDecimal (java.math.BigDecimal)12 CallableStatement (java.sql.CallableStatement)12 Test (org.junit.jupiter.api.Test)12 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)11 UnitTest (nl.topicus.jdbc.test.category.UnitTest)9 StringContains.containsString (org.hamcrest.core.StringContains.containsString)9 Date (java.sql.Date)7 DisplayName (org.junit.jupiter.api.DisplayName)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5