码迷,mamicode.com
首页 > 数据库 > 详细

scala实现读取Oracle数据

时间:2015-04-21 12:50:52      阅读:334      评论:0      收藏:0      [点我收藏+]

标签:

用scala实现读取oracle数据

增加oralce的jar包后

package cn.bigdata.scala.oracle

import java.sql.{DriverManager, Connection, ResultSet}

object ConnectOracle {
 
   val user="youname"
    val password = "youpwd"
    val conn_str = "jdbc:oracle:thin:@ip:1521:database";

  println(conn_str)
   def main(args:Array[String]): Unit ={
    //classOf[com.mysql.jdbc.Driver]
    Class.forName("oracle.jdbc.OracleDriver")//.newInstance();
    val conn = DriverManager.getConnection(conn_str,user, password)
    println("hello")
    try {
      val st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)
      // Execute Query
       val rs = st.executeQuery("select *  from table t where t.Fdsid = ‘1002‘")
      // Iterate Over ResultSet
      while (rs.next) {
        println(rs.getString("cloumn"))
      }
    }
    catch {
      case _ : Exception => println("===>")
    }
    finally {
      conn.close
    }
  }
}    

  

scala实现读取Oracle数据

标签:

原文地址:http://www.cnblogs.com/zhanggl/p/4443841.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!