Skip to main content

Posts

Showing posts from 2021

SCALA : Scala code to Call Data from Oracle Data Source and Convert them to CSV files

 Hi All, Below is the code which is used to run the query from Oracle Database and load them to CSV files using Scala. object Main {     def main(args: Array[String]): Unit = {       /* Local connection details*/     val dbUser = "dbusernameo"     val dbPassword = "dbpassword"     val dbURL = "jdbc:oracle:thin:@11.2.4.80:1234:databasename"       val configQuery =       """       SELECT First_Name,Last_Name,Middle_Name,Student_Number       ,Grade_Level,Enroll_Status,Gender       from Students Where rownum<2         """     val conConfig = OracleConnect.connJdbc(dbUser, dbPassword, dbURL)       val statement = conConfig.createStatement()   ...

SCALA: Function to load the Data From Data Frame to CSV File using Scala

Hi All,   Below is the code which can be created as csv.scala file and can be called inside your MAIN Scala function to push the data from Data Frame to CSV files. import au.com.bytecode.opencsv.CSVWriter import java.time.format.DateTimeFormatter import org.apache.commons.io.FilenameUtils import java.io.FileWriter   object CSVExport {     def exportCSVFile (oracleUser: String,oraclePassword: String,oracleURL: String,oracleOutPutFilePath:String,oracleOutPutFileDateFormat:String,oracleQueryFilePath:String): Unit = {       /* Read date part from the date pattern*/     val dateNow: String = DateTimeFormatter.ofPattern(oracleOutPutFileDateFormat).format(java.time.LocalDate.now)       /* Reconstruct the new file name*/     val basename = FilenameUtils.getBaseName(oracleOutPutFilePath)     val extension = FilenameUtils....

Scala: Function to create Oracle Connection

 Hi All, We can use, below code to create a function in SCALA to connect to Oracle Database and call this function on your main SCALA by passing the parameter.  Please be sure to install the necessary drivers - oracle JDBC pool drivers   def connJdbc (oracleUser: String,oraclePassword: String,oracleURL: String): java.sql.Connection = {     val ods = new OracleDataSource()     ods.setUser(oracleUser)     ods.setURL(oracleURL)     ods.setPassword(oraclePassword)     ods.getConnection()   } }