本文整理汇总了Scala中java.sql.ResultSetMetaData类的典型用法代码示例。如果您正苦于以下问题:Scala ResultSetMetaData类的具体用法?Scala ResultSetMetaData怎么用?Scala ResultSetMetaData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResultSetMetaData类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: JdbcSchemaFns
//设置package包名称以及导入依赖的类
package io.eels.component.jdbc
import java.sql.{ResultSet, ResultSetMetaData}
import com.sksamuel.exts.Logging
import io.eels.component.jdbc.dialect.JdbcDialect
import io.eels.schema.{Field, StructType}
object JdbcSchemaFns extends Logging {
def fromJdbcResultset(rs: ResultSet, dialect: JdbcDialect): StructType = {
val md = rs.getMetaData
val columnCount = md.getColumnCount
logger.trace(s"Resultset column count is $columnCount")
val cols = (1 to columnCount).map { k =>
Field(
name = md.getColumnLabel(k),
dataType = dialect.fromJdbcType(k, md),
nullable = md.isNullable(k) == ResultSetMetaData.columnNullable
)
}
StructType(cols.toList)
}
}
开发者ID:51zero,项目名称:eel-sdk,代码行数:29,代码来源:JdbcSchemaFns.scala
示例2: OracleJdbcDialect
//设置package包名称以及导入依赖的类
package io.eels.component.jdbc.dialect
import java.sql.{ResultSetMetaData, Types}
import com.sksamuel.exts.Logging
import io.eels.component.jdbc.JdbcReaderConfig
import io.eels.schema.{BooleanType, ByteType, DataType, DecimalType, DoubleType, Field, FloatType, IntType, LongType, Precision, Scale, ShortType}
class OracleJdbcDialect extends GenericJdbcDialect with Logging {
private val config = JdbcReaderConfig()
// oracle uses its own timestamp types
override def sanitize(value: Any): Any = {
if (value == null) null
else value match {
case other if other.getClass.getName == "oracle.sql.TIMESTAMP" =>
value.getClass.getDeclaredMethod("timestampValue").invoke(value)
case other => super.sanitize(other)
}
}
override def toJdbcType(field: Field): String = field.dataType match {
// https://docs.oracle.com/cd/E19501-01/819-3659/gcmaz/
case BooleanType => "NUMBER(1)"
case IntType(_) => "NUMBER(10)"
case LongType(_) => "NUMBER(19)"
case FloatType => "NUMBER(19, 4)"
case DoubleType => "NUMBER(19, 4)"
case ByteType(_) => "NUMBER(3)"
case ShortType(_) => "NUMBER(5)"
case _ => super.toJdbcType(field)
}
private def decimalType(column: Int, metadata: ResultSetMetaData): DataType = {
val precision = metadata.getPrecision(column)
val scale = metadata.getScale(column)
require(scale <= precision, "Scale must be less than precision")
(precision, scale) match {
// Jdbc returns precision == 0 and scale == -127 for NUMBER fields which have no precision/scale
// http://stackoverflow.com/questions/593197/what-is-the-default-precision-and-scale-for-a-number-in-oracle
case (0, _) => DecimalType(config.defaultPrecision, config.defaultScale)
case (_, -127L) => DecimalType(config.defaultPrecision, config.defaultScale)
case (x, 0) if x > 9 => LongType.Signed
case (_, 0) => IntType.Signed
case (_, _) => DecimalType(Precision(precision), Scale(scale))
}
}
override def fromJdbcType(column: Int, metadata: ResultSetMetaData): DataType = {
metadata.getColumnType(column) match {
case Types.DECIMAL | Types.NUMERIC => decimalType(column, metadata)
case _ => super.fromJdbcType(column, metadata)
}
}
}
开发者ID:51zero,项目名称:eel-sdk,代码行数:58,代码来源:OracleJdbcDialect.scala
注:本文中的java.sql.ResultSetMetaData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论