---
title: "用客户端连接项目中嵌入的derby数据库方法"
author: "youjin"
date: "2012-12-28T11:12:10Z"
tags: ["Derby", "嵌入式数据库"]
categories: ["数据库"]
slug: "derby"
draft: false
lastmod: "2012-12-28T11:11:18Z"
id: 1756235
url: "https://youjin.iteye.com/blog/1756235"
---

  最近，做网站静态化辅助项目，打算将需要静态化的url存入内嵌式数据库里。第一次使用derby，下面把如何用客户端（选择coolsql，可以选择其他工具）连接程序中的derby方法，分享下：
   1.程序中创建数据库时，如果没有指定目录，会默认在项目的根目录下，生成一个以derby数据库名的目录，如：
  Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
			System.out.println("Load the embedded driver");
			Connection conn = null;
			Properties props = new Properties();
			props.put("user", "test");
			props.put("password", "test");
			// create and connect the database named helloDB
			conn = DriverManager.getConnection(
					"jdbc:derby:testDB;create=true", props);
			System.out.println("create and connect to testDB");
			conn.setAutoCommit(true);

其中：“jdbc:derby:testDB;create=true”，则在项目根目录下生成一个testDB目录。
 2.下载安装coolsql后，操作如下：
   1>新建一个书签，选择驱动
     找到derby-10.9.1.0.jar（或其他版本jar），选择下面的：org.apache.derby.jdbc.EmbeddedDriver 。
   2>下一步，输入用户名、密码，填写程序中赋值的：test，test；下面的数据库名字填写时，要注意，写系统的绝对路径，如：E:\eclipse3.7\wordspace_mvn\staticize\testDB（staticize为项目根目录），下面的url：jdbc:derby:E:\eclipse3.7\wordspace_mvn\staticize\testDB（自动填写）。
   3>保持连接就可以了。