KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > test > cases > TestOther


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.cases;
6
7 import java.sql.Connection JavaDoc;
8 import java.sql.DriverManager JavaDoc;
9 import java.sql.PreparedStatement JavaDoc;
10 import java.sql.ResultSet JavaDoc;
11 import java.sql.Types JavaDoc;
12
13 public class TestOther {
14     public static void main(String JavaDoc[] args) {
15         Object JavaDoc[] tos = {
16 // new int[] {1, 2, 3, 4, 5},
17
// new Integer(122), // Uncomment to see a "Hexadecimal string with odd number of characters"
18
new String JavaDoc[] {"hello", "world"}, // Uncomment to see a "Deserialization failed"
19
// new Integer(12) // Will save it somehow, but fails to retrieve
20
};
21
22         try {
23             Class.forName("org.h2.Driver");
24             Connection JavaDoc con = DriverManager.getConnection("jdbc:h2:mem:", "sa", "");
25             con.setAutoCommit(true);
26
27             con.createStatement().executeUpdate("CREATE TABLE TestOtherJDBC (tstData OTHER)");
28             System.out.println("table created");
29
30             PreparedStatement JavaDoc stmt = con.prepareStatement("INSERT INTO TestOtherJDBC (tstData) VALUES (?)");
31
32             for (int i = 0; i < tos.length; i++) {
33                 System.out.println(tos[i].getClass().getName() + "\t" + tos[i]);
34                 stmt.setObject(1, tos[i], Types.OTHER);
35                 stmt.executeUpdate();
36             }
37             System.out.println("inserted");
38
39             ResultSet JavaDoc rs = con.createStatement().executeQuery("SELECT tstData FROM TestOtherJDBC");
40
41             while(rs.next()) {
42                 Object JavaDoc obj = rs.getObject(1);
43                 System.out.println(obj.getClass().getName() + "\t" + obj);
44             }
45             rs.close();
46         } catch (Throwable JavaDoc e) {
47             e.printStackTrace();
48         }
49
50     }
51 }
52
Popular Tags