我有一个clojure项目,我想用它来使用h2数据库。有没有办法检查数据库是否存在?我试过这样的事情:
(defn mysql-db []
(if (.exists (clojure.java.io/as-file "my-webapp.h2.db"))
(println "exists")
(j/with-connection
{:classname "org.h2.Driver"
:subprotocol "h2:file"
:subname "db/my-webapp"}
(j/create-table :locations
[:id "bigint primary key auto_increment"]
[:title "varchar (255)"]
[:part "clob"])
(j/insert-records :locations
{:title "Steven Gerrard: I'm not the new Beckham"
:part "He might not have the Becks appeal -- but Steven Gerrard says he's ready to light up Hollywood in his own way..."}))))
但是.exists
函数总是返回false。
答案 0 :(得分:1)
我改变了
byte[] content = getContent(packet.getData());
if (content.length > 0) {
InputStream byteIS = new ByteArrayInputStream(content);
SessionInputBufferImpl contentBuf = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), content.length);
contentBuf.bind(byteIS);
ChunkedInputStream chunkedIS = new ChunkedInputStream(contentBuf);
GZIPInputStream gzipIS = new GZIPInputStream(chunkedIS);
while (gzipIS.available() != 0) {
byte[] buf = new byte[128];
gzipIS.read(buf);
contentBuilder.append(new String(buf, "UTF-8"));
}
gzipIS.close();
String contentString = contentBuilder.toString();
}
进入
(if (.exists (clojure.java.io/as-file "my-webapp.h2.db"))
它有效。我想我没有找到正确的文件夹。