KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > databaseclassloader > emc


1 // simple test file
2
package org.apache.derbyTesting.databaseclassloader;
3
4
5 import java.sql.*;
6 import java.io.*;
7
8 public class emc
9 {
10   // version 2 of the app, set the ok flag.
11

12   public static void addContact(int id, String JavaDoc contact)
13     throws SQLException
14   {
15        Connection conn = DriverManager.getConnection("jdbc:default:connection");
16        PreparedStatement ps = conn.prepareStatement(
17          "INSERT INTO EMC.CONTACTS(id, e_mail, ok) VALUES(?, ?, ?)");
18
19        ps.setInt(1, id);
20        ps.setString(2, contact);
21
22        // simple check ok = 1 not ok = 0
23
int ok = contact.toLowerCase().indexOf("spam") == -1 ? 1 : 0;
24        ps.setInt(3, ok);
25        ps.executeUpdate();
26        ps.close();
27        conn.close();
28   }
29   public static String JavaDoc getSigners(String JavaDoc name) throws Exception JavaDoc {
30     Class JavaDoc clazz = Class.forName(name);
31  
32     Object JavaDoc[] signers = clazz.getSigners();
33
34     if (signers == null)
35        return null;
36
37     String JavaDoc description = null;
38     for (int i = 0; i < signers.length; i++)
39     {
40       Object JavaDoc ocert = signers[i];
41       if (ocert instanceof java.security.cert.X509Certificate JavaDoc)
42       {
43          java.security.cert.X509Certificate JavaDoc cert =
44                 (java.security.cert.X509Certificate JavaDoc) ocert;
45
46
47          String JavaDoc by = cert.getSubjectDN().getName();
48
49          if (description == null)
50              description = by;
51          else
52              description += "," + by;
53        }
54       else
55      {
56       System.out.println("signed " + ocert.getClass());
57     }
58
59     }
60
61     return description;
62   }
63
64   public static void main(String JavaDoc[] args) throws Exception JavaDoc
65   {
66     System.out.println("Signed By " + getSigners(args[0]));
67   }
68
69   /**
70     Get a resource out of the jar file.
71   */

72   public static String JavaDoc getArticle(String JavaDoc path)
73     throws IOException
74   {
75      InputStream is = emc.class.getResourceAsStream(path);
76
77      if (is == null)
78         return null;
79
80      InputStreamReader isr = new InputStreamReader(is, "US-ASCII");
81
82      LineNumberReader lnr = new LineNumberReader(isr);
83
84      String JavaDoc result = lnr.readLine();
85
86      lnr.close();
87
88      return result;
89  
90   }
91 }
92
Popular Tags