在Eclipse下,从安装到使用Derby插件

Ubuntu Comments(76)

正文:为什么选择Derby?Derby数据库的性能比较:PDF文档,点击下载



本文参考资料:
http://www.cecs.csulb.edu/~monge/classes/share/usingEclipseDerby.html
http://www.ibm.com/developerworks/opensource/library/os-ad-eclipse/
http://db.apache.org/derby/integrate/plugin_howto.html
http://db.apache.org/derby/papers/DerbyTut/ij_intro.html

装Derby Plugin到Eclipse:
首先从Derby下载页面 查找最新官方发布的版本(或者需要的版本),下载derby_core_pluginderby_ui_plugin这两个必须的Eclipse插件下载到计算,并解压缩到Eclipse目录下的plugins文 件夹下。注意,压缩包中所有文件可能都默认在plugin文件夹下,所以解压缩後,將得到plugin文件夹(也可能会叫plugin(1))下的所有文 件拷贝到eclipse安装目录下的plugin文件夹中。
被拷贝的文件应该是
org.apache.derby.core_10.6.2, org.apache.derby.ui_1.1.2, 和 org.apache.derby.plugin.doc_1.1.2这样3个名称的(根据下载选择,版本好会有不同)。

使用Derby同Eclipse
首 先,添加DerbyJava项目。运行Eclipse(如果Eclipse在安装Derby前就开着,请重新启动Eclipse)。在Package Explorer中选择Java项目,右键,依次选择Apache Derby,Add Apache Derby nature.到此,添加Derby完成。
你可以再次在项目上点击右键,Apache Derby,选择sysInfo(Derby System Information),便能在Eclipse的控制台输出中看到Derby系统信息。如下:

------------------ Java Information ------------------
Java Version:    1.6.0_18
Java Vendor:     Sun Microsystems Inc.
Java home:       /usr/local/jdk1.6.0_18/jre
Java classpath:  /windows/E/Computer Study/Software Study/Programming/Eclipse Workspace On Ubuntu 10.10/AccountManagement/bin:/opt/eclipse/plugins/org.apache.derby.core_10.6.2/derbytools.jar:/opt/eclipse/plugins/org.apache.derby.core_10.6.2/derby.jar:/opt/eclipse/plugins/org.apache.derby.core_10.6.2/derbynet.jar:/opt/eclipse/plugins/org.apache.derby.core_10.6.2/derbyclient.jar
OS name:         Linux
OS architecture: i386
OS version:      2.6.35-22-generic
Java user name:  knowyourself1010
Java user home:  /home/knowyourself1010
Java user dir:   /windows/E/Computer Study/Software Study/Programming/Eclipse Workspace On Ubuntu 10.10/AccountManagement
java.specification.name: Java Platform API Specification
java.specification.version: 1.6
java.runtime.version: 1.6.0_18-b07
--------- Derby Information --------
JRE - JDBC: Java SE 6 - JDBC 4.0
[/opt/eclipse/plugins/org.apache.derby.core_10.6.2/derby.jar] 10.6.2.1 - (999685)
[/opt/eclipse/plugins/org.apache.derby.core_10.6.2/derbytools.jar] 10.6.2.1 - (999685)
[/opt/eclipse/plugins/org.apache.derby.core_10.6.2/derbynet.jar] 10.6.2.1 - (999685)
[/opt/eclipse/plugins/org.apache.derby.core_10.6.2/derbyclient.jar] 10.6.2.1 - (999685)
------------------------------------------------------
----------------- Locale Information -----------------
------------------------------------------------------
在选择sysInfo的同时,能看到一个叫ij(Interactive SQL)的选项,顾名思义,这是Derby提供的结构查询语言脚本的运行工具,用来执行SQL脚本语句。选择它,Eclipse的控制台会显示:
ij version 10.6
ij>
在选择sysInfo的位置选择start Derby Network Server启动Derby网络服务,接着就可以在eclipse控制台中ij>後输入SQL脚本语句了。
首先,按照http://db.apache.org/derby/papers/DerbyTut/ij_intro.html#ij_create 创建一个数据库命令如下:
ij> connect 'jdbc:derby:MyDbTest;create=true';
如果得到:IJ ERROR: Unable to establish connection的提示,可能是你的Derby Network Server没有开启。
如果执行成功,刷新PackageExplorer中的项目目录,便能看到一个名为MyDbTest的文件夹和一个derby.log文件。可以打开derby.log文件瞧瞧。
在ij中输入help;可以查看帮助:
ij> help;
 
 Supported commands include:
 
  PROTOCOL 'JDBC protocol' [ AS ident ];
                               -- sets a default or named protocol
  DRIVER 'class for driver';   -- loads the named class
  CONNECT 'url for database' [ PROTOCOL namedProtocol ] [ AS connectionName ];
                               -- connects to database URL
                               -- and may assign identifier
  SET CONNECTION connectionName; -- switches to the specified connection
  SHOW CONNECTIONS;            -- lists all connections
  AUTOCOMMIT [ ON | OFF ];     -- sets autocommit mode for the connection
  DISCONNECT [ CURRENT | connectionName | ALL ];
                               -- drop current, named, or all connections;
                               -- the default is CURRENT
 
  SHOW SCHEMAS;                -- lists all schemas in the current database
  SHOW [ TABLES | VIEWS | PROCEDURES | FUNCTIONS | SYNONYMS ] { IN schema };
                               -- lists tables, views, procedures, functions or synonyms
  SHOW INDEXES { IN schema | FROM table };
                               -- lists indexes in a schema, or for a table
  SHOW ROLES;                  -- lists all defined roles in the database,
                               -- sorted
  SHOW ENABLED_ROLES;          -- lists the enabled roles for the current
                               -- connection (to see current role use
                               -- VALUES CURRENT_ROLE), sorted
  SHOW SETTABLE_ROLES;         -- lists the roles which can be set for the
                               -- current connection, sorted
  DESCRIBE name;               -- lists columns in the named table
 
  COMMIT;                      -- commits the current transaction
  ROLLBACK;                    -- rolls back the current transaction
 
  PREPARE name AS 'SQL-J text'; -- prepares the SQL-J text
  EXECUTE { name | 'SQL-J text' } [ USING { name | 'SQL-J text' } ] ;
                               -- executes the statement with parameter
                               -- values from the USING result set row
  REMOVE name;                 -- removes the named previously prepared statement
 
  RUN 'filename';              -- run commands from the named file
 
  ELAPSEDTIME [ ON | OFF ];    -- sets elapsed time mode for ij
  MAXIMUMDISPLAYWIDTH integerValue;
                               -- sets the maximum display width for
                               -- each column to integerValue
 
  ASYNC name 'SQL-J text';     -- run the command in another thread
  WAIT FOR name;               -- wait for result of ASYNC'd command
 
  GET [SCROLL INSENSITIVE] [WITH  {HOLD | NOHOLD}] CURSOR name AS 'SQL-J query';
                               -- gets a cursor (JDBC result set) on the query
                               -- the default is a forward-only cursor with holdability
  NEXT name;                   -- gets the next row from the named cursor
  FIRST name;                  -- gets the first row from the named scroll cursor
  LAST name;                   -- gets the last row from the named scroll cursor
  PREVIOUS name;               -- gets the previous row from the named scroll cursor
  ABSOLUTE integer name;       -- positions the named scroll cursor at the absolute row number
                               -- (A negative number denotes position from the last row.)
  RELATIVE integer name;       -- positions the named scroll cursor relative to the current row
                               -- (integer is number of rows)
  AFTER LAST name;             -- positions the named scroll cursor after the last row
  BEFORE FIRST name;           -- positions the named scroll cursor before the first row
  GETCURRENTROWNUMBER name;    -- returns the row number for the current position of the named scroll cursor
                               -- (0 is returned when the cursor is not positioned on a row.)
  CLOSE name;                  -- closes the named cursor
  LOCALIZEDDISPLAY [ ON | OFF ];
                               -- controls locale sensitive data representation
 
  EXIT;                        -- exits ij
  HELP;                        -- shows this message
 
 Any unrecognized commands are treated as potential SQL-J commands and executed directly.

输入show connections;可以看到当前链接,如下:
ij> show connections;
CONNECTION0* -     jdbc:derby:MyDbTest
* = current connection

接在来根据ij介绍,在当前数据库(MyDbTest)中创建表derbyDB,并增加修改数据,控制台输入输出如下:
ij> create table derbyDB(num int, addr varchar(40));
0 rows inserted/updated/deleted
ij> insert into derbyDB values (1956,'Webster St.');
1 row inserted/updated/deleted
ij> insert into derbyDB values (1910,'Union St.');
1 row inserted/updated/deleted
ij> select * from derbyDB;
NUM        |ADDR                                   
----------------------------------------------------
1956       |Webster St.                            
1910       |Union St.                              

2 rows selected
ij> update derbyDB set num=180,addr='Grand Ave.' where num=1956;
1 row inserted/updated/deleted
ij> select * from derbyDB;
NUM        |ADDR                                   
----------------------------------------------------
180        |Grand Ave.                             
1910       |Union St.                              

2 rows selected
依次执行下面命令,断开链接并退出ij:
ij> disconnect;
ij> show connections;
No connections available.
ij> exit;
另,执行SQL脚本文件的命令为:
ij> run 'my_file.sql';

在程序中链接MyDbTest数据库的命令有:
Connection conn =DriverManager.getConnection("jdbc:derby:MyDbTest");
或者:
jdbc:derby:../otherDirectory/MyDbTest
jdbc:derby:directory:MyDbTest
jdbc:derby:jar:(c:/derby/lib/jar2.jar)MyDbTest

更多链接方式请见:http://db.apache.org/derby/docs/dev/devguide/cdevdvlp34964.html

► Install Tomcat 6.x + JDK/JRE + Eclipse 3.5.x(Galileo) under Ubuntu 9.10

Ubuntu Comments(4)

2010年02月29日

本文作者163博客链接

这几天试着在Ubuntu上试着配置Eclipse,期间走了不少弯路。

如果选择Ubuntu自动下载安装的Eclipse将会因为其eclipse文件路径设置不同而无法为其成功添加Srever。

如果选择Ubuntu自动下载安装的Tomcat将会因为其文件夹存放路径不同而无法为Eclipse添加Server。

最后我选择手动下载eclipse-jee-galileo-SR2-linux-gtk.tar.gz安装,手动下载apache-tomcat-6.0.26.tar.gz安装。最后成功在Eclipse中完成添加server: Tomcat 6.0。

 

继续阅读

► Ubuntu 8.04 修改启动目录/boot/grub/menu.lst

Ubuntu Comments(0)

2009年01月30日 15:19

当我更新了当前版本(Ubuntu 8.04)的Ubuntu的内核后,启动目录列表中会出现新的选项,而旧的选项不会自己去掉。于是我的启动目录便有了3个Ubuntu 8.04的不同内核版本的启动选项。

Ubuntu 8.04.3 LTS, kernel 2.6.24-26-generic
Ubuntu 8.04.3 LTS, kernel 2.6.24-26-generic (recovery mode)

Ubuntu 8.04.3 LTS, kernel 2.6.24-24-generic
Ubuntu 8.04.3 LTS, kernel 2.6.24-24-generic (recovery mode)
Ubuntu 8.04.3 LTS, kernel 2.6.24-19-generic
Ubuntu 8.04.3 LTS, kernel 2.6.24-19-generic (recovery mode)
Ubuntu 8.04.3 LTS, memtest86+
Other operating systems:
Microsoft Windows XP Professional


 

于是我在应用程序中 附件中 打开终端程序(Applications-> Accessories -> Terminal)

输入sudo gedit /boot/grub/menu.lst

 

继续阅读