Some summary of Derby database

Source: Internet
Author: User

This paper summarizes some problems in the development process of OSGi, in which the configuration of DBCP data source is configured under SPRINGDM.
One, the built-in mode of the Derby data source
The main application of this mode is embedded program, because it is small, and do not open 1527 port (the Derby database default port), you can directly use the program to connect with the database. Its configuration under SPRINGDM is as follows:
① Absolute Path Database configuration
<bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" init-method= "CreateDataSource" destroy-method= "Close" > <property name= "driverclassname" value= "Org.apache.derby.jdbc.EmbeddedDriver"/          > <property name= "url" value= "Jdbc:derby:f:\\java\\derby\\database\\firstdb;create=true"/> </bean>
② Relative database path configuration (in relation to the project's total directory)
<bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" init-method= "CreateDataSource" destroy-method= "Close" > <property name= "driverclassname" value= "Org.apache.derby.jdbc.EmbeddedDriver"/ > <property name= "url" value= "Jdbc:derby:.. \\darwin;create=true "/> </bean>
Note: 1. When eclipse runs, it means that the application is using the Derby database, so the IJ tool again connects to the database with an error because a derby database can only be occupied by one application.
2. If you write a db.bundle to connect to the database, you must add <dynamicimport-package>*</dynamicimport-package&gt to its pom file; Error: Unable to load driver class (no dynamic Introduction package, of course, cannot load!) )
3. If the application is finished, remember to close the database.
public static void CloseDatabase (Connection conn) {try {if (conn!=null) {conn.close ();} Tip: After a successful shutdown of the database, the Getconnection () method throws an exception to notify Drivermanager.getconnection ("Jdbc:derby:;shutdown=true"); SYSTEM.OUT.PRINTLN ("database is closed");} catch (SQLException se) {if ((se.geterrorcode () = = 50000) && ("XJ015". Equals (Se.getsqlstate ())))) {//We got the Expected ExceptionSystem.out.println ("Derby shut down normally");//Note that for single database shutdown, the expected// SQL state is ' 08006 ', and the error code is 45000.} else {System.err.println ("Derby did not shut down normally");}}}

Some summary of Derby database

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.