如何将 JavaDB 数据库集成到我的主 java 包中
我正在开发一个使用 JavaDB 的桌面应用程序。 我正在使用 NetBeans 6.8 和 JDK 6 Update 20,
我创建了我需要的数据库,并使用 ClientDriver
通过我的应用程序连接到它:
String driver = "org.apache.derby.jdbc.ClientDriver";
String connectionURL = "jdbc:derby://localhost:1527/myDB;create=true;user=user;password=pass";
try {
Class.forName(driver);
} catch (java.lang.ClassNotFoundException e) {
e.printStackTrace();
}
try {
schedoDBConnection = DriverManager.getConnection(connectionURL);
} catch (Exception e) {
e.printStackTrace();
}
这工作正常。但在这种情况下,数据库的服务来自 NetBeans。如果我将应用程序移至另一台电脑,我将无法访问我的数据库。如何将 JavaDB 集成到我的应用程序中?
I am working on a desktop application which uses JavaDB.
I am using NetBeans 6.8 and JDK 6 Update 20
I created the database I need and connected to it through my application using ClientDriver
:
String driver = "org.apache.derby.jdbc.ClientDriver";
String connectionURL = "jdbc:derby://localhost:1527/myDB;create=true;user=user;password=pass";
try {
Class.forName(driver);
} catch (java.lang.ClassNotFoundException e) {
e.printStackTrace();
}
try {
schedoDBConnection = DriverManager.getConnection(connectionURL);
} catch (Exception e) {
e.printStackTrace();
}
This works fine. But in that case the service of the database comes from NetBeans. If I move my application to another PC I won't be able to access my database. How can I integrate my JavaDB into my application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NetBeans 以 网络服务器 模式启动 Derby,并且 Derby 运行在另一个 JVM。如果要将数据库嵌入到应用程序中,则需要在 嵌入模式在您的应用程序中。为此,请使用
derby.jar
提供的EmbeddedDriver
。默认情况下,将从工作目录创建/加载数据库。如果您想要更多控制,建议的方法是设置 derby.system.home 系统属性。查看在桌面应用程序中使用 Java DB。
另请参阅
NetBeans starts Derby in Network Server mode and Derby is running in another JVM. If you want to embed your database inside an application, you'll need to start Derby in embedded mode from within your application. To do so, use the
EmbeddedDriver
provided byderby.jar
.By default, the database will be created/loaded from the working directory. If you want more control, the recommended way is to set the
derby.system.home
system property. Have a look at Using Java DB in Desktop Applications.See also
该数据库不是来自 Netbeans;而是来自 Netbeans。它内置于 JDK 本身中。
客户端需要有可用的 JDBC 驱动程序 JAR。如果您将数据库作为服务器运行,您的用户将必须启动服务器。也许这就是 Netbeans 正在为您做的、必须被替换的部分。
The database isn't coming from Netbeans; it's built into the JDK itself.
Clients need to have the JDBC driver JAR available to them. If you're running the database as as server, your users will have to start the server. Maybe that's the piece that Netbeans is doing for you that will have to be replaced.
创建 db derby 并与 localhost 连接后,您需要在文件 derby.properties 中添加行,定位到您的目录数据库
保存并转到 netbeans 中的连接并将 localhost 更改为您的 ipaddress
after you create db derby and connect with localhost you need add line in file derby.properties locate in you directory database
save and go to connection in netbeans and change localhost to you ipaddress