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> 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