一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

JSP页面中连接IBM Cloudscape(derby)数据库

时间:2008-01-12 编辑:简简单单 来源:一聚教程网

以前写过一个jsp页面中连接mysql的例子
连接derby时,只是jdbc的连接属性有所改变,大同小异而已。
derby数据库与mysql不同的是,它有两种连接方式:embbed 和 net server
这里只用了第一种embbed的形式,第二种还没有试过。
系统运行环境:winxp+jdk1.4.2+tomcat+cloudscape10.0
以下是具体的网页代码:

derbyconnect.jsp

<%@ page language="java" import="java.sql.*" import="java.util.Properties" %>
<%
String databaseURL ="jdbc:derby:C:DatabasejimmyDB"; //C:DatabasejimmyDB是数据库的存放位置
try{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); //derby数据库的embbed驱动名
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");//新建数据库
properties.put("user", "APP");//用户名
properties.put("password", "APP"); //密码
properties.put("retreiveMessagesFromServerOnGetMessage", "true");
//Get a connection
Connection connect= DriverManager.getConnection(databaseURL, properties);
out.print("Success connect derby server!");
Statement s = connect.createStatement();
s.execute("create table jimmyDB2(num int, addr varchar(40))");

out.println("Created table jimmyDB2");
s.execute("insert into jimmyDB2 values (1956,'Webster St.')");
out.println("Inserted 1956 Webster");
s.execute("insert into jimmyDB2 values (1910,'Union St.')");
out.println("Inserted 1910 Union");

热门栏目