Derby database is a pure memory database implemented in Java and is an open-source project of Apache. Because it is implemented in Java, it can be run on any platform. Another feature is that it is small in size and free of installation. You only need a few small jar packages to run it.
The Derby database has two running modes:
1) embedded mode. The Derby database shares the same JVM with the application, which is usually started and stopped by the application. It is invisible to other applications except the ones that start it, that is, other applications cannot access it;
2) network mode. The Derby database exclusively occupies one JVM and runs as an independent process on the server. In this mode, multiple applications are allowed to access the same Derby database.
On Apache, Derby has four release packages. Here we use the bin release package as an example. The bin release package contains script files, demos, and jar files for executing the Derby database tool, setting the Derby database environment.
Here I use the myeclipse development environment, and the derby driver is provided by myeclipse.
To enable the Derby server, you must first enable tomcat.
1. Create a derby Database
In the menu bar of myeclipse, choose Window> show View> other...
Select dB browser-> OK
In the DB browser window, right-click New...
Go to the following page:
Next or directly finish.
Then, myderby appears in the DB browser window. Right-click and open connection (or click the connection button next to it)
After the connection is successful, you can create a table in the database (two methods are available, as shown below)
1. Click "myderby" and the drop-down list "connected to myderby" appears.
Right-click connected to myderby and click New SQL editor. Then, you can write the corresponding SQL language in the SQL window.
2. In the connected to myderby drop-down list, there are apps and nullid. You can create data tables graphically in the drop-down list.
How can I use the database in JSP?
1. First import the C:/user/. myeclipse/libs/derby_10.2.2.0/derbyclient. Jar driver to your JSP project webroot/WEB-INF/
2. Compile the JSP file with the following code:
Code:
- <% @ Page contenttype = "text/html; charset = gb2312" %>
- <% @ Page import = "Java. SQL. *" %>
- <HTML>
- <Head>
- <Title> database operation </title>
- </Head>
- <Body>
- <%
- Connection conn = NULL;
- Try
- {
- Class. forname ("org. Apache. Derby. JDBC. clientdriver ");
- String url = "JDBC: Derby: // 127.0.0.1: 1527/mydb; Create = true ";
- Conn = drivermanager. getconnection (URL, "name", "password ");
- Statement ST = conn. createstatement ();
- Resultset rs=st.exe cutequery ("select * From loginmsg ");
- While (Rs. Next ())
- {
- Out. println ("" + Rs. getstring (1 ));
- Out. println ("" + Rs. getstring (2 ));
- }
- }
- Catch (exception E)
- {
- Out. println ("some error ");
- Out. println ("e. getmessage ()");
- }
- %>
- </Body>
- </Html>
Run the command to check whether the operation is successful.