jython zxJDBC UCanAccess Driver Class? - jdbc

Trying to get the combo jython-zxJDBC-UCanAccess working on my Windows machine; been driving me nuts the entire day as I keep getting
zxJDBC.DatabaseError ( driver [net.ucanaccess.jdbc.UcanaccessDriver] not found ), and
zxJDBC.DatabaseError ( driver [ucanaccess] not found )
I had been using this sample code from Gord Thompson with my particulars - keeps failing with driver-not-found errors whatever I try:
from com.ziclix.python.sql import zxJDBC
#Or also import ucanaccess
jdbc_url = "jdbc:ucanaccess://Z:/Companies.accdb"
username = ""
password = ""
driver_class = "net.ucanaccess.jdbc.UcanaccessDriver"
#Or driver_class = "net.ucanaccess.jdbc.UcanloadDriver"
cnxn = zxJDBC.connect(jdbc_url, username, password, driver_class)
crsr = cnxn.cursor()
crsr.execute("SELECT * FROM tblSICs")
for row in crsr.fetchall():
print row[0]
crsr.close()
cnxn.close()
Jython alone works well, I use it with the SikuliX IDE
'from ... import zxJDBC' passes without error
UCanAccess works fine from the command line (console.bat) with my MS
Access database; all 5 JARs are in and as in the CLASSPATH variable
What I don't get is what is "driver_class"?. I thought that the database-specific driver gets located by means of Jython/SikuliX looking in CLASSPATH, where the '.../ucanaccess-5.0.0.jar' is seen.
Here the CLASSPATH:
"c:\Users\User\AppData\Roaming\UCanAccess\lib\hsqldb-2.5.0.jar;c:\Users\User\AppData\Roaming\UCanAccess\lib\jackcess-3.0.1.jar;c:\Users\User\AppData\Roaming\UCanAccess\lib\commons-lang3-3.8.1.jar;c:\Users\User\AppData\Roaming\UCanAccess\lib\commons-logging
-1.2.jar;c:\Users\User\AppData\Roaming\UCanAccess\ucanaccess-5.0.0.jar"
And here is where the SikuliX IDE looks for resources:
D:\Drawer 3\Sikuli\Training\UCanAccess.sikuli Z:\test.sikuli
C:\Users\User\AppData\Roaming\Sikulix\Lib\site-packages
C:\Users\User\AppData\Roaming\Sikulix\Lib
C:\Users\User\AppData\Roaming\Sikulix\Extensions\Lib
C:\Users\User\AppData\Roaming\Sikulix\Extensions\jython-standalone-2.7.2.jar\Lib
classpath
pyclasspath/
Does anyone spot the issue?

Issue was found to be a special twist of SikuliX 2.0.4 which cannot evaluate the CLASSPATH variable. Here the workarounds / SiluliX' way to get to know the location of JARs:
Two Solutions:
Solution A
SikuliX IDE looks into the folder
<C:\Users\User\AppData\Roaming\Sikulix\Extensions>; all five relevant
JAR files need to be places in that folder (no 'lib' subfolder as in
the deployment pack):
ucanaccess-5.0.0.jar
commons-lang3-3.8.1.jar
commons-logging-1.2.jar
hsqldb-2.5.0.jar
jackcess-3.0.1.jar
Check the extension JARs that get found by seeing
SikuliX->Tools->Extensions...
Solution B
Leave the needed JARs in their original deployment folder, and add
their path to the 'Special File'
'C:\Users\User\AppData\Roaming\Sikulix\Extensions\extensions.txt' as:
ucanaccess = C:/Users/User/AppData/Roaming/UCanAccess/ucanaccess-5.0.0.jar
C:/Users/User/AppData/Roaming/UCanAccess/lib/commons-lang3-3.8.1.jar
C:/Users/User/AppData/Roaming/UCanAccess/lib/commons-logging-1.2.jar
C:/Users/User/AppData/Roaming/UCanAccess/lib/hsqldb-2.5.0.jar
C:/Users/User/AppData/Roaming/UCanAccess/lib/jackcess-3.0.1.jar
This will be evaluated, as a workaround, instead of the CLASSPATH
variable
Thanks for your help!

Related

Perl script compiled as Windows executable does not connect to Oracle

I have a Perl Script that I've written that connects to Oracle. The script works perfectly on my machine with PERL64 installed. I tried to turn this script into an EXE using ActiveState PerlApp. Again, works perfectly on my machine. Once the executable is on a machine that does not contain Perl it is missing DLL's needed to connect to Oracle.
use DBI;
# CONFIG VARIABLES
our $database = "database.app.net";
our $host = "server.app.net";
our $port = "1522";
our $user = "SVC_app";
our $pw = 'Password';
# DATA SOURCE NAME
our $dsn = "dbi:Oracle:$host:$port/$database";
# PERL DBI CONNECT
our $connect = DBI->connect($dsn, $user, $pw);
# PREPARE THE QUERY
our $query = 'SELECT Blah FROM database."table" where "blah" = ?';
our $query_handle = $connect->prepare($query);
# EXECUTE THE QUERY
$query_handle->execute($value);
# BIND TABLE COLUMNS TO VARIABLES
$query_handle->bind_columns(undef, \$return);
# LOOP THROUGH RESULTS
while($query_handle->fetch()) {
#print "$return";
}
The error i receive is :
Can't load 'auto/DBD/Oracle/Oracle.dll' for module DBD::Oracle: load_file:The specified module could not be found at/DynaLoader.pm line 224.
Thanks in advance
There are two cases:
If you do NOT have the DLL files on the target machine, it's not going to work. DLL files aren't linked into the executables (as the name says, they're Dynamic Link Libraries, not static libraries)
If you DO have the DLL files on the target machine, but they're not found then there are a few possible explanations. The files may not be in the PATH, for instance. Or the files may not have the correct permissions, especially if you're calling your executable from something like a service (which by default runs on a system account which has different permissions).
Also, keep in mind that Window is a bit picky about DLL files. It may say that Oracle.dll is missing, but what is actually missing may be one of its dependencies. Maybe OCI.dll ?
And if you have more than one DLL file with the same name, try and make sure which one is loaded, because it may not be the right version.
If the files are there, there's only one version of them, they're in the PATH and it still cannot find them, you can try registering the files manually by running the regsvr32 command on the required DLL.
You need to separately install the Oracle client on any machine that you are running your EXE on.
PerlApp in the ActiveState's PDK will not wrap Oracle clients into the EXE because doing so will violate Oracle's re-distribution agreement.

Using sbt-native-packager, how can I simply prepend a directory to my bash script's ${app_classpath}?

My project uses sbt-native-packager with packageArchetype.java_application.
During sbt stage I have a task that generates some final Typesafe style configuration file that I then copy to:
target/universal/stage/conf/application.conf
I'd like to prepend this directory to the runtime classpath in the bash script, and am looking for the simplest way to do that. I'd hate to maintain a separate src/main/templates/bash-template for something so simple, and am not seeing exactly how to go about it otherwise.
Thanks!
Short Answer
Define a package mapping
mappings in Universal <+= (packageBin in Compile, sourceDirectory ) map {
(_, src) =>
// we are using the reference.conf as default application.conf
// the user can override settings here
val conf = src / "main" / "resources" / "reference.conf"
conf -> "conf/application.conf"
}
Create a jvmopts in src/universal/conf with
-Dconfig.file=/<installation-path>/conf/application.conf
Add to build.sbt
bashScriptConfigLocation := Some("${app_home}/../conf/jvmopts")
Example for server_archetype:
Follow the example application. A bit of description can be found here.
Long answer
Changing the classpath is not supported directly by the sbt-native-packager, because it can cause problems like
classpath ordering
security issues
Like Typesafe Config, most libraries which use config files, provide a parameter to define the location of the configuration file. Use the parameters describe in the documentation.
It seems your are trying to run a server, which means you can use the
packageArchetype.java_server
which is designed to read external configurations. Take a look at the example application how to use it.
The following setting:
scriptClasspath in bashScriptDefines ~= (cp => "../conf" +: cp),
Allows you to do exactly what you need.
In this specific example I prepend the "../conf" directory to the classpath entries.
Also, you need to import the following configuration keys to your build SBT:
import com.typesafe.sbt.packager.Keys.bashScriptDefines
import com.typesafe.sbt.packager.Keys.scriptClasspath
The question you asked in the title is a bit different from the description. I am answering the question in the title here - i.e. how can you prepend a directory into the classpath:
This is very hacky and brittle in that it will probably break if/when the sbt-native-packager makes changes to how the script is generated, but for now it works for me:
private lazy val ClasspathPattern = "declare -r app_classpath=\"(.*)\"\n".r
bashScriptDefines := bashScriptDefines.value.map {
case ClasspathPattern(classpath) => "declare -r app_classpath=\"/path/to/some/external/lib/*:" + classpath + "\"\n"
case _#entry => entry
},

Get executable path of a jar in java 7

Before everybody tells me this is a duplicate, please hear me out...
When you need the absolute executable path from inside a running jar (= path to self) regardless of the current working directory, in the old days (Java 6 JRE 1.6) this used to work like a charm:
getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
Nowadays in Java 7 (JRE 1.7) this just returns "./". If you want to test this, you'll need to create a runnable jar because when compiling from the source, you will get the path as expected.
This is driving me mad as I have been searching for a solution for what seems like an eternity. I resorted to hardcoding the absolute path, but obviously that means the jar is not portable.
Does anyone know what to do?
Thanks!!!
Just stumbled across the same problem after exporting one of my older Java 6 projects which also used the same method to get the execution path.
Here's a quick workaround (replace 'Start.class' with your class name or use 'getClass()'):
String path = Start.class.getProtectionDomain().getCodeSource().getLocation().getPath();
path = new File(rootFolder).getAbsolutePath();
Most likely you will end up with a path still ending with a period. So you might want to fix that using:
if (path.endsWith(".")) path = path.substring(0, path.length() - 1);
Tested using Oracle JRE 7 on Windows 7 64bit and Xubuntu 14.04

HBase ERROR: hbase-default.xml file seems to be for and old version of HBase (null)

I am trying to write a program to connect to HBase. However when I execute following command
HBaseConfiguration.create(); I get following error: .
"hbase-default.xml file seems to be for and old version of HBase (null), this version is 0.92.1-cdh4.1.2.
When I dig deep and debug inside observe following:
class HBaseConfiguration
private static void checkDefaultsVersion(Configuration conf) {
if (conf.getBoolean("hbase.defaults.for.version.skip", Boolean.FALSE))return;
String defaultsVersion = conf.get("hbase.defaults.for.version");
String thisVersion = VersionInfo.getVersion();
if (!thisVersion.equals(defaultsVersion)) {
throw new RuntimeException(
"hbase-default.xml file seems to be for and old version of HBase (" +
defaultsVersion + "), this version is " + thisVersion);
}
}
In my case HBase returns default version as null, I am not sure why its returning as null as I checked the corresponding entry in hbase-default.xml packaged with the HBase.jar it has correct entry.
When I try the same thing from a standalone program it works as expected.
Guyz, Please let me know if you have any questions.
Thanks in advance,
Rohit
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property>
<name>hbase.defaults.for.version.skip</name>
<value>true</value>
</property>
</configuration>
Add this to a hbase-default.xml and put the file in the classpath or resource foldr. I got it when i ran from within spring hadoop environment. By adding above file to reosurce folder of the job jar i was able to solve tis-
finally found the workaround to this problem...
The problem is hbase-default.xml is not included in your classpath.
I added hbase-default.xml in target/test-classes ( it will vary in your case ), you can just add hbase-default.xml in various folder and see what works for you.
NOTE : This is just workaround, not the solution
Solution will be load the proper jars ( which I haven't figured out yet )
I've been getting this error using HBase1.1.1.
I created a simple HBase client and it worked fine. Then I built a simple RMI service, and that worked fine. But when I tried putting my simple HBase query code into RMI service I started getting this error on the HBaseConfiguration.create() call. After playing a bit, I found that the HBaseConfiguration.create() call works OK if placed before the security manager stuff that is in my main(). I get the error if the call is placed after block of code containing security manager calls...
Configuration conf = HBaseConfiguration.create(); // This works
if(System.getSecurityManager() == null)
{
System.setSecurityManager(new SecurityManager());
} // End if
// Configuration conf = HBaseConfiguration.create(); // This fails
I get the error if the create() call happens in main() after that security manager block, or in code within the class that is instantiated by main(). I don't get the error if create() is called within a static{ } block in my RMI service class (which I believe gets called before main()), or in main() before the security manager block, as shown.
BTW, the jar files that I include in my class path in order to get a minimal client to run are the following:
commons-codec-1.9.jar,
commons-collections-3.2.1.jar,
commons-configuration-1.6.jar,
commons-lang-2.6.jar,
commons-logging-1.2.jar,
guava-12.0.1.jar,
hadoop-auth-2.5.1.jar,
hadoop-common-2.5.1.jar,
hbase-client-1.1.1.jar,
hbase-common-1.1.1.jar,
hbase-hadoop2-compat-1.1.1.jar,
hbase-it-1.1.1-tests.jar,
hbase-protocol-1.1.1.jar,
htrace-core-3.1.0-incubating.jar,
log4j-1.2.17.jar,
netty-all-4.0.23.Final.jar,
protobuf-java-2.5.0.jar,
slf4j-api-1.7.7.jar,
slf4j-log4j12-1.7.5.jar
Had a similar problem where the error was
java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (0.98.3-hadoop2), this version is Unknown
at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:70)
at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:102)
at org.apache.hadoop.hbase.HBaseConfiguration.create(HBaseConfiguration.java:113)
In my case I had same set of jar files at two different levels of classpath, removed from one level and it worked fine.
In my case the issue was caused by old java version (1.5), which was default on the server. But it works fine with 1.7.
In my code, I used this to solve my error.
val config = HBaseConfiguration.create() //error
val config = new Configuration() //works

Where should jpos.xml be located for JavaPos Tomcat app.?

I am trying to add in a new driver to our system running under Tomcat. The vendor has provided a JavaPos driver, my question is where to put the jpos.xml file so Tomcat can find it?
I tried putting it in tomcat\common\classes but still get a JPOSException
"Service does not exist in loaded JCL registry" when I try to open it. Help!
Yes correct, JavaPOS. I'm integrating JavaPos into an existing client side Tomcat app., and would like to know the correct place (in the expanded war file) to put jpos.xml and also jpos.properties.
Thanks a lot, fred.
I Don't know if this would help a five year old question!
/*
* If you want to place the jpos.xml file elsewhere on your local file
* system then uncomment the following line and specify the full path to
* jpos.xml.
*
* If you want to place the jpos.xml file on a webserver for access over the
* internet then uncomment the second System.setProperty line below and
* specify the full URL to jpos.xml.
*/
System.setProperty( JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME, "jpos.xml" );
//System.setProperty(JposPropertiesConst.JPOS_POPULATOR_FILE_URL_PROP_NAME, "http://some-where-remote.com/jpos.xml");
System.setProperty("jpos.loader.serviceManagerClass", "jpos.loader.simple.SimpleServiceManager");
System.setProperty("jpos.util.tracing.TurnOnNamedTracers", "JposServiceLoader,SimpleEntryRegistry,SimpleRegPopulator,XercesRegPopulator");
System.setProperty("jpos.util.tracing.TurnOnAllNamedTracers", "ON");
I think you are talking about JavaPOS, not jPOS?

Resources