About Derby:
http://db.apache.org/derby/
There are two ways to connect to Derby, one is a embedded connection, and the other is a derby network connection.
The steps are simple, probably three steps:
1. Instantiating JDBC Driver
2. Create a connection string
3. Connection.
About the first step:
Embedded Mode connection:
The driver used in this way is the embedded driver that is taken from it. stored in Derby.jar. Needs to be added to the classpath.
String Driver = org.apache.derby.jdbc.EmbededDriver;
Class.forName (Driver). newinstance ();
Network way:
It is a clientdriver with Derby, which is stored in Derbyclient.jar and needs to be added to the classpath.
String Driver = org.apache.derby.ClientDriver;
Class.forName (Driver). newinstance ();
This initializes a JDBC driver.
And then start creating the connection string,
Step Two:
The connection string is mainly composed of three parts, protocol, database, property.
For Derby, Protocol is Jdbc:derby.
The database is the name of the user, it is best to give the full path of the database, so that you can avoid the failure to find databases.
The above is a way of embedded connection, when for Netword client connection, need to precede the database with//localhost:1527, 1527 is Derby's network connection default port.
As for property, it describes some of the parameter values for connecting and creating databases, such as Create=true, User=username, password=pwd, separated by semicolons. Of course, these property are optional.
Examples of the above two connection string creation methods:
Embedded
' Jdbc:derby:/home/haitao/derby/mydb;create=true;user=zht;password=pwd '
Network:
' Jdbc://localhost:1527//home/haitao/derby/mydb;create=true;user=zht;password=pwd '
At last. It's the only connection to the database.
Step Three:
Very simple
Connection conn = drivermanager.getconnection (URL);
This completes the connection to the Derby database.
Then you can manipulate the database, for developers, the upper interface is the same, as long as the connection is successful, the following processing is the same.
Notes:
1. In Derbytools.jar, there is a self-contained tool that can execute a connection, SQL statement, IJ.
We can also perform related database operations in IJ.
2. When you want to start Derby's network server, you can start directly from Derbynet.jar,
The following command can be:
JAVA–CP Derbynet.jar Org.apache.derby.drda.NetworkServerControl Start