rg.codehaus.groovy.control.MultipleCompilationErrorsException when I have 2 different jdbc jars on classpath [duplicate] - sql-server-2008

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Manifest.MF issue with MSSQLSERVER 2008 and Groovy
I have a very simple groovy script with 2 database connections:
One db connection to Oracle
Another db connection to SQLServer
Problem
When I run the program through the GGTS Editor (The groovy and grails version of SpringSource Tool Suite), the two queries run and return results fine. But, when I run the program from the command line, from the project folder as follows:
groovy -cp lib\jtds-1.3.0.jar lib\ojdbc6-11g.jar src\Starter.groovy
I get the following error:
C:\workspace-ggts\Test>groovy -cp lib\jtds-1.3.0.jar lib\ojdbc6-11g.jar src\Star
ter.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\workspace-ggts\Test\lib\ojdbc6-11g.jar: 1: unexpected char: 0x3 # line 1, col
umn 3.
PK♥ ßî∟9 ♦ META-INF/■╩ ♥ ☻ PK♥♦ ßî∟9 ¶ M
ETA-INF/MANIFEST.MF?æ┴N├0►D∩æ≥☼½₧α►7)R[rúΘÑá☻R½^æq6─òcç╡SΦ▀π4◄ → ─╒3;π}╗µ
Z▬h]┤C▓╥Φ¶↕▬ç┴¬¬§V¿↔w■╤ï:7ö┬♥qí►2C╡íôtf▌Jº0♣│╧ƒ┼öφ9
^
1 error
What I have Tried
I have tried using the jtds driver to connect to SQLServer as I thought the problem was the sqljdbc4.jar from Microsoft site based on this same problem reported differently here
I have tried putting semicolons to separate the classpath dependencies, and still same error.
I have upgraded java version to 1.7. Groovy version is 2.0.5
From the IDE it runs fine, but from command line I get the error.
If I comment out one of the db access code (connection, query, println of resultset) leaving my groovy script with only one db connection & access the program runs fine from command line. For example:
This
groovy -cp lib\jtds-1.3.0.jar src\Starter.groovy
or this:
groovy -cp lib\ojdbc6-11g.jar src\Starter.groovy
does work. As soon as I add the code and the jar in the classpath for that second db access I get the error reported above.
I am out of thoughts or ideas

Files in your classpath need to be separated with a semi-colon on Windows. On unix-like platforms like Linux or OSX, the separator is a colon. Groovy is treating the second jar file as the script, and the script name as the first command line parameter.
Try this:
groovy -cp lib\jtds-1.3.0.jar;lib\ojdbc6-11g.jar src\Starter.groovy
Do you get a different error with that?

Related

apache drill: "no current connection" error and "could not find or load main class sqlline.sqlline" error

I am using JDK: 1.8.0.281 and Drill: 1.18.0 on m1 Mac.
I cannot start drill downloaded from https://drill.apache.org/download/ directly. It says
could not find or load main class sqlline.sqlline. So I refer to https://github.com/julianhyde/sqlline/issues/69, download and compile sqlline and add these two lines
BINPATH=/Users/fields/Repositories/sqlline-sqlline-1.9.0/bin
exec java -cp $BINPATH/../target/sqlline-1.9.0-jar-with-dependencies.jar sqlline.SqlLine "$#"
to the beginning of drill/bin/sqlline. Then I start drill-embedded and get no current connection every time I enter a query.
Please help me identify the problem. Thanks a lot!!!

migrate Apache OFBiz from Apache Derby to mysql

I am using ofbiz in my organization. I want to migrate ofbiz from derby to MySQL.
I refer the steps from
(https://cwiki.apache.org/confluence/display/OFBIZ/How+to+migrate+OfBiz+from+Derby+to+MySQL+database) here, but at the i got stuck at the end.
At the end when I type (java -jar ofbiz.jar -install) this command I am getting an exception,
C:\Users\sagar_vinod_khanke\Sagar\Apache OFBiz\Ofbiz\13.07>java -jar ofbiz.jar -
install
Exception in thread "main" org.ofbiz.base.start.StartupException: Couldn't not f
etch config instance
at org.ofbiz.base.start.Start.init(Start.java:202)
at org.ofbiz.base.start.Start.main(Start.java:127)
Caused by: java.io.IOException: Cannot load configuration properties : org/ofbiz
/base/start/-install.properties
at org.ofbiz.base.start.Config.getPropertiesFile(Config.java:229)
at org.ofbiz.base.start.Config.readConfig(Config.java:297)
at org.ofbiz.base.start.Config.getInstance(Config.java:58)
at org.ofbiz.base.start.Start.init(Start.java:200)
... 1 more
Can you please help me?
don't use - with install.
See revised Step-V
Step-V
1. Run the following command from command prompt:
java -jar ofbiz.jar install
2. Start OfBiz
3. Use webtools to import all data from XML:
a. Navigate to http://localhost:8080/catalog/
b. Go to Applications>WebTools
c. Go to section 'Entity XML Tools' and click the link 'XML Data Import Dir' -> In the 'Absolute directory path:' enter the full path of the directory where you exported the data in Step - II

Manifest.MF issue with MSSQLSERVER 2008 and Groovy

I have created a simple Groovy project in GGTS IDE that connects to Oracle and SQLServer. The Program runs fine within the IDE but when I run the program through the command line I seem to get some sort of enconding error in MANIFEST.MF?. See the stacktrace below:
Command Line
groovy -cp lib\ojdbc14_g.jar lib\sqljdbc4.jar src\Starter.groovy
Result
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
C:\workspace-ggts-3.1.0.RELEASE\Test\lib\sqljdbc4.jar: 1: unexpected char: 0x3 # line 1, column 3.
PK♥ h?I# ¶ META-INF/MANIFEST.MF¡|GôΓ┌▓εⁿD∞ ░=x/êsä 8◄o ï∟B▲
ë╔
^
1 error
In the past to connect to MSSQLServer I have used the following jars:
msbase.jar
msutil.jar
mssqlserver.jar
This time though, when I looked for jdbc jars for 2008 I got the sqljdbc4.jar. Again it works from within the IDE but not from command line. I have singled out the problem to be in the sqljdbc4.jar because I commented all the code related to that and the program ran fine with just the oracle jar references.
Anybody know why this is happening?
What jars are you using to connect to sqlserver 2008 from the command line with groovy?
Thanks.
You need semi-colons between classpath entries (assuming you are on Windows)
groovy -cp lib\ojdbc14_g.jar;lib\sqljdbc4.jar src\Starter.groovy
Or colons if you're on Linux/Mac
groovy -cp lib/ojdbc14_g.jar:lib/sqljdbc4.jar src/Starter.groovy

Tomcat JDBC MySQL ClassNotFoundException

I would like to use springMVC and JPA (using hibernate) on my tomcat 7 server (running locally on my Mac).
I was able to set up everything successfully with an embedded H2 database.
Now I switched to mysql and am getting the following error
java.lang.ClassNotFoundException: "com.mysql.jdbc.Driver"
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
This suggests tomcat is having trouble finding the mysql-connector for java.
There are a multitude of tutorials on how to add the connector to $CATALINA_HOME/lib.
After trying to use a maven dependency for my project, I followed the advice and copied the .jar file into the lib directory:
$ ls $CATALINA_HOME/lib/mysql*.jar
/Users/david/Applications/tomcat/lib/mysql-connector-java-5.1.20-bin.jar
I have read and execute permissions on the directory and file.
At the moment I can't figure out how to make tomcat aware of the jar. The folder is included in
$CATALINA_HOME/conf/catalina.properties
and I have restarted the server multiple times.
Thanks for you help.
Normally, the output of a CNFE is as follows:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
whereas your error message shows
java.lang.ClassNotFoundException: "com.mysql.jdbc.Driver"
I think you've still got quotes around the driver class name in your config.

How to register a JDBC driver using jruby-complete.jar?

I'm trying to write a script that is executed with the jruby-complete.jar like so:
java -cp derby.jar; -Djdbc.drivers=org.apache.derby.jdbc.EmbeddedDriver -jar jruby-complete.jar -S my_script.rb
I'm using JVM 1.6.0_11 and JRuby 1.4.
In my jruby script I attempt to connect to the database like this.
connection = Java::com.sql.DriverManager.getConnection("jdbc:derby:path_to_my_DB")
This throws a java.sql.SQLException: "No suitable driver found" exception.
I've tried manually loading the driver into the class loader using Class.forName which gives me the same error.
It looks like to me that the class loader being used by the DriverManager is not the same as the current thread's. I've tried setting the current thread's class loader using:
JThread = java.lang.Thread
...
class_loader = JavaLang::URLClassLoader.new(
[JavaLang::URL.new("jar:file:/derby.jar!/")].to_java(
JavaLang::URL),JRuby.runtime.jruby_class_loader)
JThread.currentThread().setContextClassLoader(class_loader )
But this doesn't help.
Any ideas?
OK I downloaded jruby-complete.jar and had a go....
This seems to work for me:
java -classpath c:\ruby\db-derby-10.5.3.0-bin\lib\derby.jar;jruby-complete-1.4.0.jar org.jruby.Main -S derby.rb
When using the -jar switch, the -classpath option is ignored (maybe the CLASSPATH shell var is too). But on the above line, we put both required jars on the class path and pass the class name to execute (i.e. org.jruby.Main). The script being passed in is as per my other answer.
Another option (which I have not tried) would be to alter the jruby-complete.jar manifest file to specify as classpath, as described here:
Adding Classes to the JAR File's Classpath
First, make sure your driver jar is not corrupted (this made me waste a couple of days one time).
Second, read this about JRuby/Java classloade: JRuby Wiki
Third (because I haven't played with "jruby-complete") try this simple script and then see if you can adapt as you need.
require 'java'
require 'C:\ruby\db-derby-10.5.3.0-bin\lib\derby.jar' # adjust for your machine
include_class "java.sql.DriverManager"
derby = org.apache.derby.jdbc.EmbeddedDriver.new
connection = DriverManager.getConnection("jdbc:derby:derbyDB;create=true")