Connecting to the IBM Cloudscape (derby) database on the JSP page

Source: Internet
Author: User
I used to write an example of connecting to mysql on a jsp page.
When connecting to derby, the connection property of jdbc is changed, which is similar.
Unlike mysql, the derby database has two connection methods: embbed and net server.
The first embbed format is used here, and the second one has not been tried yet.
System running environment: winxp + jdk1.4.2 + tomcat + cloudscape10.0
The specific webpage code is as follows:
<Html>
<Head> <title> derbyconnect. jsp </title> <Body>
<% @ Page language = "java" import = "java. SQL. *" import = "java. util. Properties" %>
<%
String databaseURL = "jdbc: derby: C: DatabasejimmyDB"; // C: DatabasejimmyDB is the storage location of the database.
Try {
Class. forName ("org. apache. derby. jdbc. EmbeddedDriver"); // The embbed driver name of the derby database
Out. println ("Success loading derby Driver! ");
}
Catch (Exception e)
{
Out. print ("Error loading derby Driver! ");
E. printStackTrace ();
}
Try {
Properties properties = new Properties ();
Properties. put ("create", "true"); // create a database
Properties. put ("user", "APP"); // user name
Properties. put ("password", "APP"); // password
Properties. put ("retreiveMessagesFromServerOnGetMessage", "true ");
// Get a connection
Connection connect = DriverManager. getConnection (databaseURL, properties );
Out. print ("Success connect derby server! ");
Statement s = connect. createStatement ();
S.exe cute ("create table jimmyDB2 (num int, addr varchar (40 ))");

Out. println ("Created table jimmyDB2 ");
S.exe cute ("insert into jimmyDB2 values (1956, 'Webster St .')");
Out. println ("Inserted 1956 Webster ");
S.exe cute ("insert into jimmyDB2 values (1910, 'Union St .')");
Out. println ("Inserted 1910 Union ");
Related Article

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.