用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 } } }
时间: 2024-10-06 20:06:10