2

I'd like to store a database schema in its own file, and have my Scala code retrieve it (and execute it via JDBC).

It seems to me that sbt wants me to store the file as: src/main/resources/packagename/my.sql. Putting it there, I see it's in the jar - but I can't seem to access it from Scala.

Specifically, getClass().getResource("my.sql") returns a null pointer, and so does any other form I can think of.

How should I load the file? Or is there a better way to do it?

SRobertJames
  • 131
  • 2
  • 6
  • 3
    Have you tried `getClass().getResource("/my.sql")` (with slash)? or maybe `getClass().getResource("/packagename/my.sql")` (if sql file is placed in some pacage)? – tenshi Jan 28 '11 at 20:39

2 Answers2

1

I had an almost identical problem. The only difference is my file is in src/main/resources (without any packages). This worked for me.

val is:InputStream = Github.getClass().getResourceAsStream( "/repo.json" );
Frankie Ribery
  • 11,933
  • 14
  • 50
  • 64
-1

Why don't you generate a file, and store it as "my.sql", and later search for it, where it appears in the filesystem?

user unknown
  • 35,537
  • 11
  • 75
  • 121