Sunday, October 17, 2010

Database Drivers and JDK specifications

On different oracle jdbc bundles. Must read:
http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html#02_07
Why couldnt I understand the naming convention of jars before:

ojdbc6.jar - All the classes to support basic functionality for the Thin and OCI drivers when using JDK 1.6 (JSE 6)
ojdbc5.jar - All the classes to support basic functionality for the Thin and OCI drivers when using JDK 1.5 (JSE 5)
classes12.jar - Classes for the Thin and OCI drivers when using a Java 1.2 or 1.3 VM.
ojdbc14.jar - Same as classes12.jar except for use with Java 1.4 VMs

More dependencies for OCI:
libocijdbc.so (Solaris)Native library for the JDBC OCI driver.

* for JDBC 8.x.x drivers, the is 8
* for JDBC 9.x.x drivers, the is 9
* for JDBC 10.x.x drivers, the is 10
* for JDBC 11.x.x drivers, the is 11

This file should be locatable via your LD_LIBRARY_PATH setting.

ocijdbc.dll (Windows)Similar to above, except on Windows platforms. This file should be locatable via your %PATH% setting.

Monday, June 28, 2010

Working with Java LDAP API

import java.io.Serializable;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

import org.apache.log4j.Logger;



/**
* @author Kiran
*
*/
public class LDAPInfo implements Serializable {

private static Logger log = Logger
.getLogger(LDAPInfo.class);
private final static String CLASS_NAME = "LDAPInfo";
private static final long serialVersionUID = 19931047L;

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String userName = null;
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://dsxstage.mycompany.com:389");
// env.put(Context.SECURITY_AUTHENTICATION,"OU=ccoentities,O=cco.mycompany.com");
env.put(Context.SECURITY_PRINCIPAL,"liferay_stage.gen"); // specify the username
env.put(Context.SECURITY_CREDENTIALS,"1!f3ray"); // specify the password
DirContext ctx = new InitialDirContext(env);
Attributes matchAttrs = new BasicAttributes(true);
log.info("The Connection Established to the LDAP Server Succeessfully");
log.info("Now trying to search the values in the LDAP Server");

userName = "kiran";
Attributes answer = ctx.getAttributes("uid="+userName+", OU=ccoentities,O=cco.mycompany.com");

for (NamingEnumeration ae = answer.getAll(); ae.hasMore();) {
Attribute attr = (Attribute)ae.next();
System.out.println("attribute: " + attr.getID());
/* Print each value */
for (NamingEnumeration e = attr.getAll(); e.hasMore();
System.out.println("value: " + e.next()))
;
}


Attribute at = null;
// at.
// matchAttrs.put(attr);

//NamingEnumeration answer = ctx.search("Country",matchAttrs);


//ctx.getSchema("")
// ctx.bind(name, obj)
//ctx.search(name, matchingAttributes);


} catch(NamingException ex) {

log.error("The Exception while connecting to the LDAP Server is:"+ ex.getMessage());
ex.printStackTrace();


} catch(Exception ex) {
log.error("The Exception while retrieving the attribute values from the LDAP Server is:"+ ex.getMessage());
ex.printStackTrace();


}
}

}

Thursday, June 24, 2010

Getting the Manifest Version inside a Jar File

/**
*
*/



import java.io.File;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.logging.Logger;


/**
* @author Kiran
*
*/


public class JarFileVersionInfoNew {

/**
* A logger for this class.
**/
private static final Logger LOG =
Logger.getLogger(JarFileVersionInfoNew.class.getName());



/**
* Displays the attributes contained in the manifest of one (or
* several jar files...
*
* @param args a list of jar file.
*/
public static void main(String[] args) {
final String path = "C:/Documents and Settings/kkanapar/Workspaces/WSRP/liferay-portal-new/lib/global";
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
System.out.println("Number of files and directories in the file system You gave: " + listOfFiles.length);
for (int i = 0; i < listOfFiles.length; i++) {
String tempFileName = null;
if (listOfFiles[i].isFile()) {
tempFileName = listOfFiles[i].getName();
System.out.println("File " +"-"+i+": "+ tempFileName);
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " +"-"+i+": "+ listOfFiles[i].getName());
}



final File f = new File(path+"\\"+tempFileName);
if (!f.canRead()) {
System.err.println(f.getAbsolutePath()+": no such file");
continue;
}
try {
JarFile jar = new JarFile(f);
final Manifest manifest = jar.getManifest();
final Attributes mattr = manifest.getMainAttributes();
System.out.println(f.getAbsolutePath());
System.out.println("Main attrs: ");
for (Object a : mattr.keySet()) {
System.out.println("\t "+a+": "+mattr.getValue((Name)a));
}


System.out.println("\nReading other attrs:\n");

final Map attrs = manifest.getEntries();
for (String name : attrs.keySet()) {
final Attributes attr = attrs.get(name);
System.out.println(name+": \n");
for (Object a : attr.keySet()) {
System.out.println("\t "+a+": "+attr.getValue((Name)a));
}
}
System.out.println("\n ======================================================================================\n");

} catch (Exception x) {
System.err.println("Failed to read manifest for "+
f.getAbsolutePath()+": "+x);
}
}
}

}

Monday, April 5, 2010