KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > rmijdbc > SSLClient


1
2 package org.objectweb.rmijdbc;
3
4 /**
5  * RmiJdbc client/server JDBC Driver
6  * (C) GIE Dyade (Groupe BULL / INRIA Research Center) 1997
7  * (C) ExperLog 1999-2000
8  *
9  * @version 1.0
10  * @author Pierre-Yves Gibello (pierreyves.gibello@experlog.com)
11  * Additional SSL Support
12  * Douglas Hammond(djhammond@sympatico.ca)
13  */

14
15 import java.sql.*;
16 import java.net.InetAddress JavaDoc;
17 import java.security.*;
18 /**
19  * This is a sample program for RmiJdbc client/server jdbc Driver in SSL mode
20  * SSL is suppose to rely on Sun's JSSE (becomes standard from JDK 1.4).
21  */

22 public class SSLClient {
23
24   public static void main(String JavaDoc args[]) {
25     try {
26
27       // Change this line if you use another security provider
28
// You can also remove it if the security provider is
29
// statically registered in java.security
30
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
31
32       // Register RmiJdbc Driver in jdbc DriverManager
33
// The call to newInstance() is necessary on some platforms
34
// (with some java VM implementations)
35
Class.forName("org.objectweb.rmijdbc.Driver").newInstance();
36
37       // Test with JDBC/ODBC bridge
38
// Requires a "newtest" DSN to be properly configured
39
String JavaDoc url = "jdbc:odbc:newtest";
40
41       // RMI host will point to local host
42
// A port number may be specified as 1st argument to the program
43

44       String JavaDoc portSpec = "";
45       if(args.length > 0) {
46         Integer.parseInt(args[0]); // Check port number is an integer
47
portSpec = new String JavaDoc(":" + args[0]);
48       }
49
50       String JavaDoc rmiHost = new String JavaDoc(
51        "//" + InetAddress.getLocalHost().getHostName() + portSpec);
52
53       // RmiJdbc URL is of the form:
54
// jdbc:rmi://<rmiHostName[:port]>/<jdbc-url>
55

56       String JavaDoc jurl = "jdbc:rmi:" + rmiHost + "/" + url;
57       System.out.println("SSLClient:" + jurl);
58       Connection c = DriverManager.getConnection(jurl);
59
60       Statement st = c.createStatement();
61       ResultSet rs = st.executeQuery("select * from tb_names");
62
63       ResultSetMetaData md = rs.getMetaData();
64       while(rs.next()) {
65         System.out.print("\nTUPLE: | ");
66         for(int i=1; i<= md.getColumnCount(); i++) {
67           System.out.print(rs.getString(i) + " | ");
68         }
69       }
70
71       rs.close();
72
73     } catch(Exception JavaDoc e) {
74       e.printStackTrace();
75     }
76   }
77
78 };
79
80
Popular Tags