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() statement.setFetchSize(1000) val resultSet: java.sql.ResultSet = statement.executeQuery(configQuery) /* Read all the variable from Orcale table*/ while (resultSet.next) { // var oracl
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.getExtension(oracleOutPutFilePath) val path = FilenameUtils.getFullPath(oracleOutPutFilePath)