scala实现读取Oracle数据
用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 } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。