Thursday Mar 22, 2007

JRuby and Derby - The easy way

Are you interested in learning to use Derby from JRuby? While there are more comprehensive tutorials/classes on the web, here is a simple way to access Derby from JRuby (tested on 0.9.8). I hope you find it useful. Make sure derby.jar is in your CLASSPATH

require "java"

java.lang.Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance()
conn = java.sql.DriverManager.getConnection("jdbc:derby:test;create=true")

stmt = conn.createStatement
rs = stmt.executeQuery("select TABLEID,TABLENAME from sys.systables")

while (rs.next) do
  printf("%20s %20s\\n", rs.getString(1), rs.getString(2))
end
About

realneel

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today