The Derby database connection operation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.