Scala和sbt:在资源中存储SQL

编程入门 行业动态 更新时间:2024-10-26 22:27:14
本文介绍了Scala和sbt:在资源中存储SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将数据库模式存储在自己的文件中,让我的Scala代码检索它(并通过JDBC执行)。

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

似乎我,sbt要我将文件存储为:src / main / resources / packagename / my.sql。把它放在那里,我看到它在jar中 - 但我似乎无法从Scala访问它。

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.

具体来说,getClass()。getResource(my.sql )返回一个空指针,我能想到的任何其他形式也是如此。

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?

推荐答案

我有一个几乎相同的问题。 唯一的区别是我的文件位于 src / main / resources (没有任何包)。 这对我有用。

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" );

更多推荐

Scala和sbt:在资源中存储SQL

本文发布于:2023-07-24 13:16:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1203671.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:资源   Scala   sbt   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!