H2 java.lang.ClassNotFoundException for trigger passed in classpath - java

I'm starting the h2 server using this command:
java -Xms256M -Xmx512M -Xss1024K -cp "C:\workspaces\ProjectA\ModuleA\target;C:\Program Files (x86)\H2\bin\h2-1.4.199.jar" org.h2.tools.Server -tcp -tcpPort 80 -tcpAllowOthers -baseDir C:/database/h2/data
where in C:\workspaces\ProjectA\ModuleA\target I got jar where is my trigger class(I checked with the total commander, and I'm 100% sure it is there)
Then I open my h2 database and try to run sql on table for which I have set up trigger, but it throws:
Caused by: org.h2.message.DbException: Class "com.test.projecta.trigger.Trigger" not found [90086-199]
at org.h2.message.DbException.get(DbException.java:194).
Why is it thrown? As I understand trigger should be added to classpath and it is, so why it is not seen?

Solved: It was the problem with the way I was connecting to the database.I was specifying JDBC URL like jdbc:h2:C:\database\h2\data\database instead of doing it this way jdbc:h2:tcp://localhost:80/database

Related

How to pass configuration argument on jboss

I added db2 driver, edited module.xml in JBOSS_HOME/modules/com/ibm/main.
In this folder, I have
db2jcc4.jar
db2jcc_lecense_cu.jar
db2jcc_license_cisuz.jar
module.xml
After having these, I tried to launch JBoss console on Powershell
.\standalone.bat --server-config=standalone-full-ha.xml -Dcom.sun.CORBA.ORBDynamicStubFactoryFactoryClass=com.sun.corba.se.impl.presentation.rmi.StubFactoryFactoryStaticImpl
which I tried to handle ORB exception(related to this https://bugs.openjdk.java.net/browse/JDK-6497156)
But my jboss container is not launched. I checked the log file,
2019-09-17 296 FATAL [org.jboss.as.server] (main) WFLYSRV0239: Aborting with exit code
and error display on Powershell
WFLYSRV0073: Invalid option '.sun.CORBA.ORBDynamicStubFactoryFactoryClass=com.sun.corba.se.impl.presentation.rmi.StubFactoryFactoryStaticImpl'
It works on command prompts though. I am wondering it is correct way to pass argument like this. Thanks in advance!
Edit
I am using Java8, JBoss7.1
Powershell has issues with -D. Try this instead, notice the " around -D
.\standalone.bat --server-config=standalone-full-ha.xml "-Dcom.sun.CORBA.ORBDynamicStubFactoryFactoryClass=com.sun.corba.se.impl.presentation.rmi.StubFactoryFactoryStaticImpl"

Change System properties for h2 database

I tried to run a jar file from mainframes USS.
java -jar Batch.jar Batch.cfg
I got the below h2 exception. Looks like I don't have necessary permission to write it to /test.trace.db. I would like to change the directory so that I don't need to worry about the access. How can I specify the directory for the trace file with java -jar command?
org.h2.message.DbException: Log file error: "/test.trace.db", cause: "java.io.FileNotFoundException: /test.trace.db (EDC5111I Permission denied.)" [90034-190]
According h2 documentation, you need to update system property h2.clientTraceDirectory.
Something like java -Dh2.clientTraceDirectory=mydir -jar Batch.jar Batch.cfg

MySQL to PostgreSQL migration: mysql connector

I am trying to migrate from MySQL to PostgreSQL and I have a Java-related problem that I am not able to fix. Full disclosure: I know little or nothing about Java, but the migration uses a Java-based script, so for me it becomes a configuration problem.
Short version of the problem:
The migration tool throws this exception:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
mysql-connector-java-5.0.8-bin.jar is already in the "JAVA_HOME\jre\lib\ext" directory, and I don't know how to solve this depencency problem.
Long version of the problem:
I was trying to migrate from MySQL to PostgreSQL. I checked the official postgresql documentation and I chose the free tool from entreprisedb (that can be downloaded here) to start the migration.
From the installation readme, they tell you that the mysql connector is not installed by default, but they also tell you the steps to solve this problem:
To enable MySQL connectivity, download MySQL's freely available JDBC driver from:
http://www.enterprisedb.com/downloads/third-party-jdbc-drivers
Place the mysql-connector-java-5.0.8-bin.jar file in the "JAVA_HOME\jre\lib\ext" directory (in my case: "C:\Program Files\Java\jre1.8.0_60\lib\ext\mysql-connector-java-5.0.8-bin.jar").
After configuring the tool properly and executing the .bat, this is the error I get:
Connecting with source MySQL database server...
MTK-11009: Error Connecting Database "MySQL Server"
DB-null: java.sql.SQLException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Stack Trace:
com.edb.MTKException: MTK-11009: Error Connecting Database "MySQL Server"
at com.edb.dbhandler.mysql.MySQLConnection.<init>(MySQLConnection.java:48)
at com.edb.common.MTKFactory.createMTKConnection(MTKFactory.java:250)
at com.edb.MigrationToolkit.createNewSourceConnection(MigrationToolkit.java:5982)
at com.edb.MigrationToolkit.initToolkit(MigrationToolkit.java:3346)
at com.edb.MigrationToolkit.main(MigrationToolkit.java:1700)
Caused by: java.sql.SQLException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at com.edb.Utility.processException(Utility.java:327)
at com.edb.dbhandler.mysql.MySQLConnection.<init>(MySQLConnection.java:47)
... 4 more
...which, to my understanding, probably means that mysql-connector-java-5.0.8-bin.jar is not found.
All the links I've found online regarding the error are specific for Eclipse or other IDEs, so I have not yet been able to solve this dependency problem.
SOLUTION
With the help of a friend that masters Java, this is the solution he achieved:
To start looking for the problem, we opened the runMTK.bat. The execution line reads:
cscript //nologo "..\etc\sysconfig\runJavaApplication.vbs" "..\etc\sysconfig\edbmtk-49.config" "-Dprop=..\etc\toolkit.properties -classpath -jar edb-migrationtoolkit.jar %*"
So then we opened this runJavaApplication.vbs, and in order to know the JAVA_EXECUTABLE_PATH that the program was using, we add this line to the script:
Wscript.Echo "JAVA_EXECUTABLE_PATH = " & JAVA_EXECUTABLE_PATH
With that info, we discover that the script is using the Java folder under C:\Program Files (x86), instead of the one under C:\Program Files (where I dropped the mysql jar). So we copy the mysql-connector-java-5.0.8-bin.jar in the \ext folder of the x86, and now the script works.
Word of advice: the script is throwing errors in half of the exported tables, so all the hassle may not be worth it. BUT if anyone is interested in making this migration script work from A to Z (which has been quite a challenge), here are the details:
HOW TO
Free tool (from entreprisedb):
http://www.enterprisedb.com/downloads/postgres-postgresql-downloads
Extract the files from the zip and fun the installer (ppasmeta-9.5.0.5-windows-x64.exe) as administrator.
To enable MySQL connectivity, download MySQL's freely available JDBC driver from:
http://www.enterprisedb.com/downloads/third-party-jdbc-drivers
Place the mysql-connector-java-5.0.8-bin.jar file in the "JAVA_HOME\jre\lib\ext" directory (in my case: "C:\Program Files\Java\jre1.8.0_60\lib\ext\mysql-connector-java-5.0.8-bin.jar").
The Migration Toolkit documentation can be found:
here (online doc): https://www.enterprisedb.com/docs/en/9.4/migrate/toc.html
or here (pdf doc): http://get.enterprisedb.com/docs/Postgres_Plus_Migration_Guide_v9.5.pdf
First: modify C:\Program Files\PostgresPlus\edbmtk\etc\toolkit.properties (Info here):
SRC_DB_URL=jdbc:mysql://SOURCE-HOST-NAME/SOURCE-DB-NAME
SRC_DB_USER=********
SRC_DB_PASSWORD=********
TARGET_DB_URL=jdbc:edb://localhost:5444/DESTINATION-DB-NAME
TARGET_DB_USER=enterprisedb
TARGET_DB_PASSWORD=********
Then: execute C:\Program Files\PostgresPlus\edbmtk\bin\runMTK.bat (Info here).
runMTK.bat -sourcedbtype mysql -targetdbtype enterprisedb -allTables YOUR_DB_SCHEMA
// ...or with a limited subset of tables:
runMTK.bat -sourcedbtype mysql -targetdbtype enterprisedb -tables TABLE1,TABLE2,TABLE3 YOUR_DB_SCHEMA
In order to get this subset of tables from MySQL:
SELECT
GROUP_CONCAT(TABLE_NAME)
FROM
information_schema.tables
WHERE
TABLE_SCHEMA = 'your_db_name'

Jasperstarter Usage

I am trying to utilize Jasperstarter with MSSQL on Windows with a JDBC driver. It seems never to find or connect with this driver for some reason despite using the same Driver and URL used by iReport which does work. I can execute reports that do not access the DB, but once I add the database parameters the call fails. I do not get any info back from the call, not sure where the debug stuff goes. Are there any special path settings that need to be made to get this to work? The exec call output just returns a 1 without any failure info.
PHP exec command stream:
"C:\\Inetpub\\wwwroot\\TekEnterpriseServer\\protected\\JasperPHP/JasperStarter/bin/jasperstarter pr ./reports/maintenance.jasper -f pdf -t generic --db-driver net.sourceforge.jtds.jdbc.Driver --db-url jdbc:jtds:sqlserver://localhost/tekenterprise"
The jdbc driver must be put into the jdbc directory of the JasperStarter installation or the path to the driver jar must be specified with --jdbc-dir.
You have to specify username and password as part of the --db-url, see
http://jtds.sourceforge.net/faq.html#urlFormat
You can get verbose output with:
jasperstarter -v pr ./reports/maintenance.jasper ...

On other pc java.sql.SQLException: No suitable driver found for jdbc:sqlserver

I wrote an app and it works fine by me. But on other pc-s it throws an exception.
java.sql.SQLException: No suitable driver found for jdbc:sqlserver
I give it (only the app.jar file) to my college, and he gets this error. I give him a jdbcdriver.jar file and, nothing changed.
However I use jre7, I added a line to the code:
Class.forName("com.mysql.jdbc.Driver");
And than he gets another exception:
Error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
What can I do to run this app properly on other pc-s?
Put the jar file, containing the MySql Driver on the classpath when starting your application.
The switch is called -cp or -classpath like this:
java -cp ".;mysql.jar" my.package.Main
assuming you start your application from the root directory which is named my.package.Main. The classpath separator is the one for Windows. For unix based OSs you need to use : i guess.

Categories