KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > test > jdbc > TestDataSource


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.test.jdbc;
6
7 import java.sql.Connection JavaDoc;
8 import java.sql.Statement JavaDoc;
9
10 import org.h2.jdbcx.JdbcDataSource;
11 import org.h2.test.TestBase;
12
13 public class TestDataSource extends TestBase {
14
15     
16 // public static void main(String[] args) throws Exception {
17
//
18
// // first, need to start on the command line:
19
// // rmiregistry 1099
20
//
21
// // System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
22
// System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
23
// System.setProperty(Context.PROVIDER_URL, "rmi://localhost:1099");
24
//
25
// JdbcDataSource ds = new JdbcDataSource();
26
// ds.setURL("jdbc:h2:test");
27
// ds.setUser("test");
28
// ds.setPassword("");
29
//
30
// Context ctx = new InitialContext();
31
// ctx.bind("jdbc/test", ds);
32
//
33
// DataSource ds2 = (DataSource)ctx.lookup("jdbc/test");
34
// Connection conn = ds2.getConnection();
35
// conn.close();
36
// }
37

38     public void test() throws Exception JavaDoc {
39         deleteDb("datasource");
40
41         JdbcDataSource ds = new JdbcDataSource();
42         ds.setURL("jdbc:h2:"+BASE_DIR+"/datasource");
43         ds.setUser("sa");
44         ds.setPassword("");
45         Connection JavaDoc conn = ds.getConnection();
46         Statement JavaDoc stat = conn.createStatement();
47         stat.execute("SELECT * FROM DUAL");
48         conn.close();
49     }
50
51 }
52
Popular Tags