结论见底部:
我正在尝试使用SchemaCrawler绘制一个SQLite数据库的图表。我的设置:
OSX 10.8版
SchemaCrawler 10.5下载自Here
从甲骨文下载的Java版本1.7.0y45
sqlite版本:3.7.12 2012-04-03 19:43:07 86B8481BE7E76CCC92D14CE762D21FB69504AF
我在安装SchemaCrawler的目录中,使用以下命令行:
stebro$ java -classpath lib/*:. schemacrawler.tools.sqlite.Main /Library/Application\ Support/MyApp/Data/MyApp.db -command="select count(*) from myTable" -infolevel=maximum
SchemaCrawler 10.5
Copyright (c) 2000-2013, Sualeh Fatehi.
SchemaCrawler is a database schema discovery and comprehension tool.
You can search for database schema objects using regular expressions,
and output the schema and data in a readable text format. You can find
potential schema design issues with lint. The output serves for
database documentation is designed to be diff-ed against other database
schemas. SchemaCrawler also generates schema diagrams.
password:
java.sql.SQLException: Could not connect to database, for user null
at schemacrawler.schemacrawler.BaseDatabaseConnectionOptions.getConnection(BaseDatabaseConnectionOptions.java:93)
at schemacrawler.schemacrawler.BaseDatabaseConnectionOptions.getConnection(BaseDatabaseConnectionOptions.java:70)
at schemacrawler.tools.commandline.SchemaCrawlerCommandLine.execute(SchemaCrawlerCommandLine.java:173)
at schemacrawler.tools.commandline.SchemaCrawlerMain.main(SchemaCrawlerMain.java:93)
at schemacrawler.tools.commandline.SchemaCrawlerMain.main(SchemaCrawlerMain.java:52)
at schemacrawler.tools.sqlite.Main.main(Main.java:43)
Caused by: java.lang.IllegalArgumentException: Insufficient parameters for database connection URL: missing [database]
at schemacrawler.schemacrawler.DatabaseConfigConnectionOptions.getConnectionUrl(DatabaseConfigConnectionOptions.java:73)
at schemacrawler.schemacrawler.BaseDatabaseConnectionOptions.getConnection(BaseDatabaseConnectionOptions.java:89)
... 5 more
如果我指定-password,我会得到相同的错误,并且为-user指定不同的值也会得到相同的结果。sqlite不需要用户/密码-为什么JDBC或SchemaCrawler要求我提供一个?
附录:
下面是一系列特定的命令,这些命令创建一个简单的数据库,然后尝试用SchemaCrawler绘制它的关系图:
bash-3.2$ sqlite3 MyApp.db
sqlite3 MyApp.db
SQLite version 3.7.12 2012-04-03 19:43:07
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table smbtest(col1 integer, col2 integer);
create table smbtest(col1 integer, col2 integer);
sqlite> ^D
bash-3.2$ ~/bin/sunjava -classpath lib/*:. schemacrawler.tools.sqlite.Main -database=MyApp.db -infolevel=maximum -command=graph -outputformat=pdf -outputfile=myapp.pdf
SchemaCrawler 10.5
Copyright (c) 2000-2013, Sualeh Fatehi.
SchemaCrawler is a database schema discovery and comprehension tool.
You can search for database schema objects using regular expressions,
and output the schema and data in a readable text format. You can find
potential schema design issues with lint. The output serves for
database documentation is designed to be diff-ed against other database
schemas. SchemaCrawler also generates schema diagrams.
password:
Graphviz was not available to create the requested graph. Please reinstall
Graphviz, and make it available on the system PATH. Meanwhile, a .dot text file
has been created instead. This .dot file can be opened in any Graphviz file
viewer.
java.io.IOException: Cannot run program "dot": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at schemacrawler.tools.integration.graph.ProcessExecutor.execute(ProcessExecutor.java:124)
at schemacrawler.tools.integration.graph.GraphGenerator.generateDiagram(GraphGenerator.java:87)
at schemacrawler.tools.integration.graph.GraphExecutable.executeOn(GraphExecutable.java:123)
at schemacrawler.tools.executable.SchemaCrawlerExecutable.executeOn(SchemaCrawlerExecutable.java:87)
at schemacrawler.tools.executable.BaseExecutable.execute(BaseExecutable.java:77)
at schemacrawler.tools.commandline.SchemaCrawlerCommandLine.execute(SchemaCrawlerCommandLine.java:176)
at schemacrawler.tools.commandline.SchemaCrawlerMain.main(SchemaCrawlerMain.java:93)
at schemacrawler.tools.commandline.SchemaCrawlerMain.main(SchemaCrawlerMain.java:52)
at schemacrawler.tools.sqlite.Main.main(Main.java:43)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:135)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 9 more
最终结论:
问题在于到我的数据库的路径中有一个空格;没有反斜杠、双引号或单引号的组合,或者两者都解决了这个问题。从与我的db文件相同的目录中运行该命令就实现了这一点。空间问题可能是因为我不理解在bash中使用的正确转义序列-如果SchemaCrawler使用我的名字作为命令行的一部分来生成其他进程,我可能需要双重转义空间。
然而,应用程序确实继续要求输入我的密码,但只要按Enter键,它就可以成功地继续。
最佳答案
史提夫,
您需要这样指定数据库:
"-database=/Library/Application Support/MyApp/Data/MyApp.db"
请注意双引号以允许数据库文件路径中的空间,以及-database命令行开关。我还删除了反斜杠,因为整个开关都用双引号括起来了。
有关命令行的帮助,只需运行:
java -classpath lib/*:. schemacrawler.tools.sqlite.Main
Sualeh Fatehi,SchemaCrawler