Starting Derby Programmatically

前端 未结 1 557
梦谈多话
梦谈多话 2021-01-13 02:06

Please have a look at the following code

DataBaseConnector.java

 import java.sql.*;
 import javax.swing.*;

    public class DataBas         


        
相关标签:
1条回答
  • 2021-01-13 02:26

    This is a embedded database, which means I am taking this from one machine to another and willing to start just by double clicking on the jar file,

    In the case of derby, an embedded database means that the database runs in the JVM and writes to the file system. Which implies that you can move the jar file around like you want, but if you use an embedded database, then each machine that you run the program on will have its own separate database, and one and only one JVM can use that database at a time. Is that what you want?

    If so, the problem is the URL that the program uses. "jdbc:derby://localhost:1527/contact;create=true" is a URL that tells DriverManager to connect to a remote database. It doesn't matter that program loads the embedded driver first.

    An embedded URL in Derby looks something like this. jdbc:derby:bar;create=true which will use an embedded database in the bar directory off of the Derby system home or current working directory. For more information on embedded urls, see here connecting to a file-based derby database.

    0 讨论(0)
提交回复
热议问题