KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SSLClient


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

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

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

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

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