1 package org.apache.derbyTesting.databaseclassloader; 3 4 5 import java.sql.*; 6 import java.io.*; 7 8 public class emc 9 { 10 12 public static void addContact(int id, String 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 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 getSigners(String name) throws Exception { 30 Class clazz = Class.forName(name); 31 32 Object [] signers = clazz.getSigners(); 33 34 if (signers == null) 35 return null; 36 37 String description = null; 38 for (int i = 0; i < signers.length; i++) 39 { 40 Object ocert = signers[i]; 41 if (ocert instanceof java.security.cert.X509Certificate ) 42 { 43 java.security.cert.X509Certificate cert = 44 (java.security.cert.X509Certificate ) ocert; 45 46 47 String 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 [] args) throws Exception 65 { 66 System.out.println("Signed By " + getSigners(args[0])); 67 } 68 69 72 public static String getArticle(String 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 result = lnr.readLine(); 85 86 lnr.close(); 87 88 return result; 89 90 } 91 } 92 | Popular Tags |