emc.java :  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » databaseclassloader » Java Open Source

Java Open Source » Database DBMS » db derby 10.2 
db derby 10.2 » org » apache » derbyTesting » databaseclassloader » emc.java
// simple test file
package org.apache.derbyTesting.databaseclassloader;


import java.sql.*;

public class emc
{
  // version 2 of the app, set the ok flag.

  public static void addContact(int id, String contact)
    throws SQLException
  {
       Connection conn = DriverManager.getConnection("jdbc:default:connection");
       PreparedStatement ps = conn.prepareStatement(
         "INSERT INTO EMC.CONTACTS(id, e_mail, ok) VALUES(?, ?, ?)");

       ps.setInt(1, id);
       ps.setString(2, contact);

       // simple check ok = 1 not ok = 0
       // HACKER WOZ ERE
       //int ok = contact.toLowerCase().indexOf("spam") == -1 ? 1 : 0;
       int ok = 1;
       ps.setInt(3, ok);
       ps.executeUpdate();
       ps.close();
       conn.close();
  }
  public static String getSigners(String name) throws Exception {
    Class clazz = Class.forName(name);
 
    Object[] signers = clazz.getSigners();

    if (signers == null)
       return null;

    String description = null;
    for (int i = 0; i < signers.length; i++)
    {
      Object ocert = signers[i];
      if (ocert instanceof java.security.cert.X509Certificate)
      {
         java.security.cert.X509Certificate cert = 
                (java.security.cert.X509Certificate) ocert;


         String by = cert.getSubjectDN().getName();

         if (description == null)
             description = by;
         else
             description += "," + by;
       }
      else
     {
      System.out.println("signed " + ocert.getClass());
  }

    }

    return description;
  }

  public static void main(String[] args) throws Exception
  {
    System.out.println("Signed By " + getSigners(args[0]));
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.