Why?
I was task to create a web based password change utility application recently. The database server is oracle. Oracle offers a way to do this through its OCI APIs. Code snippet using JDBC and OCI:
Properties props = new Properties();
props.put("user", userId);
props.put("password", oldPassword);
props.put("OCINewPassword", newPassword);
String url = "jdbc:oracle:oci:@myhost:1521:orcl";
try (OracleConnection con =
(OracleConnection)
DriverManager.getConnection(url, props)) {
if(con != null){
warning = (con.getWarnings() != null)?
con.getWarnings().toString(): "SUCCESS";
}
} catch (Exception e) {
logger.
info("Exception occurred while tyring to change users password : ",e);
warning = e.getMessage();
}
return warning;
Problem
This all worked fine using my windows 7 machine. The problem came when I deployed to a linux environment. I received an UnsatisfiedLinkError exception.
Solution
I found out that OCI APIs uses native code to communicate with Oracle. On my windows 7 box, I had ORACLE_HOME set in my environment variables. On the linux machine, I didn't.
To solve the problem, you would need to download instant client from Oracle. Download the appropriate zip(32/64 bit) file for your distribution. I use TomEE as an application server. Create a setenv.sh file in TomEE_HOME/bin and add the following to it.
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib
export LD_LIBRARY_PATH
Put all the native library files you get from instant client in CATALINA_HOME/lib and restart your server. This will solve your issue.