JdbcInputFormat
.@Deprecated public class JDBCInputFormat extends JdbcInputFormat
TypeInformation>[] fieldTypes = new TypeInformation>[] {
BasicTypeInfo.INT_TYPE_INFO,
BasicTypeInfo.STRING_TYPE_INFO,
BasicTypeInfo.STRING_TYPE_INFO,
BasicTypeInfo.DOUBLE_TYPE_INFO,
BasicTypeInfo.INT_TYPE_INFO
};
RowTypeInfo rowTypeInfo = new RowTypeInfo(fieldTypes);
JDBCInputFormat jdbcInputFormat = JDBCInputFormat.buildJDBCInputFormat()
.setDrivername("org.apache.derby.jdbc.EmbeddedDriver")
.setDBUrl("jdbc:derby:memory:ebookshop")
.setQuery("select * from books")
.setRowTypeInfo(rowTypeInfo)
.finish();
In order to query the JDBC source in parallel, you need to provide a parameterized query
template (i.e. a valid PreparedStatement
) and a ParameterValuesProvider
which
provides binding values for the query parameters. E.g.:
Serializable[][] queryParameters = new String[2][1];
queryParameters[0] = new String[]{"Kumar"};
queryParameters[1] = new String[]{"Tan Ah Teck"};
JDBCInputFormat jdbcInputFormat = JDBCInputFormat.buildJDBCInputFormat()
.setDrivername("org.apache.derby.jdbc.EmbeddedDriver")
.setDBUrl("jdbc:derby:memory:ebookshop")
.setQuery("select * from books WHERE author = ?")
.setRowTypeInfo(rowTypeInfo)
.setParametersProvider(new GenericParameterValuesProvider(queryParameters))
.finish();
Row
,
ParameterValuesProvider
,
PreparedStatement
,
DriverManager
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
JDBCInputFormat.JDBCInputFormatBuilder
Deprecated.
A builder used to set parameters to the output format's configuration in a fluent way.
|
JdbcInputFormat.JdbcInputFormatBuilder
autoCommit, dbConn, dbURL, drivername, fetchSize, hasNext, LOG, parameterValues, password, queryTemplate, resultSet, resultSetConcurrency, resultSetType, rowTypeInfo, serialVersionUID, statement, username
Constructor and Description |
---|
JDBCInputFormat()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
static JDBCInputFormat.JDBCInputFormatBuilder |
buildJDBCInputFormat()
Deprecated.
|
protected Connection |
getDbConn()
Deprecated.
|
protected PreparedStatement |
getStatement()
Deprecated.
|
buildJdbcInputFormat, close, closeInputFormat, configure, createInputSplits, getInputSplitAssigner, getProducedType, getStatistics, nextRecord, open, openInputFormat, reachedEnd
getRuntimeContext, setRuntimeContext
public static JDBCInputFormat.JDBCInputFormatBuilder buildJDBCInputFormat()
@VisibleForTesting protected PreparedStatement getStatement()
getStatement
in class JdbcInputFormat
@VisibleForTesting protected Connection getDbConn()
getDbConn
in class JdbcInputFormat
Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.