2016-06-21 15 views
0

Ich habe eine SQL-Datei, die mehrere Abfragen enthält. Da es sich um eine SQL-Datei handelt, sind Abfragen mit Semikolon (;) getrennt. Ich möchte die SQL-Datei lesen und die Abfragen als Array[String] in Scala haben.Split Inhalt der Datei in Array [String] in Scala

Zum Beispiel habe ich queries.sql Datei, die Abfragen wie enthält:

select * from table1; 
select col1,col2,col3 from table1 where col1 = '' 
col2 = ''; 
select count(*) from table; 

Ich möchte die Ausgabe wie folgt aussehen:

Array("select * from table1","select col1,col2,col3 from table1 where col1 = '' col2 =' '","select count(*) from table") 

Antwort

4

Vielleicht möchten Sie dies versuchen:

import scala.io.Source 
val theArrayYouWant = Source.fromFile(<filename>).getLines.mkString.split(";") 
+0

Wo müssen Sie ersetzen '' mit etwas wie '" yourfile.sql "' – meucaa

+0

Danke, das war super schnell :), und es gibt mir genau das, was ich will. Danke – user1105412