Jasperstarter Usage - java

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 ...

Related

Unable to execute Snowflake PUT Command through Java

We are trying to load JSON files using Java from a file location to Snowflake Named Stage. Currently, the PUT command only works for ODBC and not JDBC. So is there any way to execute PUT command using Java code?
Thanks
The Snowflake JDBC Driver does support use of PUT statements for local file uploads. The following java statement is considered a valid query and the file is uploaded:
statement.executeQuery("PUT file:///tmp/foo.json #JSONSTAGE/ overwrite=true");
Running it under a logger produces logs such as the following (logs here are from JDBC driver version v3.12.2):
n.s.c.jdbc.SnowflakeFileTransferAgent$1 FINE call:778 - filePath: /tmp/foo.json
n.s.c.jdbc.SnowflakeFileTransferAgent FINE uploadFiles:1751 - Done with uploading
The JDBC driver also supports a more efficient way of uploading a stream directly, documented here.

H2 java.lang.ClassNotFoundException for trigger passed in classpath

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

Impala driver class not being found through Jaydebeapi Connection

I recently switched over from using a PC to a Mac and now for whatever reason one of my Impala drivers that worked fine is no longer found when run in Python. I keep receiving this error every time I run the script : "java.lang.RuntimeException: Class com.cloudera.impala.jdbc41.Driver not found". Please see code snippet for my connection below.
c = jaydebeapi.connect
(jclassname='com.cloudera.impala.jdbc41.Driver',
url='jdbc:impala://cloudera-impala-proxy.live.bi.xxx/;AuthMech=3;ssl=1;',
driver_args=['xxx', self.dwh_password], jars='/Users/xxx/Desktop/ImpalaJDBC41 2.jar')
Any help or suggestions are appreciated, I feel like I'm going crazy trying to get this to work.
Did you check do you have the ImpalaJDBC***.jar in your new machine.
Please check properly weather it's available at classpath/build path or not.
Edit:
You can use hive jdbc jar as well to connect with impala , just use the port of impala rather hive in jdbc url.
Looking at this error means your jar is corrupt.
First check your impalaJDBC jar
java -jar ImpalaJDBC<version>.jar
If it gives you error that means your jar is corrupt.
Download the correct jar from cloudera

Running tests on travis using mysql

I've been trying for the last week or so to make integration tests work on travis for a school project. I've debugged a fair bit of the project but now I'm blocked and need external help.
To give a bit of context, so far, I've debugged the java project so that the tests can be launched from eclipse or from maven in command line. I've worked on the travis file so that a database is created, the database scripts run and the java tests launch. However, the tests fail on travis because of a "table missing" in the database.
This is a link to our repo.
This is the travis.yml file's code:
language : java
jdk:
- oraclejdk8
service:
- mysql
before_script:
- mysql -e 'DROP DATABASE IF EXISTS koalatest'
- mysql -e 'CREATE DATABASE IF NOT EXISTS koalatest;'
- mysql -u root --default-character-set=utf8 koalatest < backend/koalacal-backend/koalacal.sql
script: cd backend && cd koalacal-backend && mvn test -X
after_success:
- bash <(curl -s https://codecov.io/bash)
The java project that is being built and run by maven is located under rootfolder -> backend -> koalacal-backend.
Here is a link to the error log maven produces on travis.
This line seems to be the source of the error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'koalatest.Calendar' doesn't exist
I have two hypothesis:
1- The sql script that creates all the tables is not being run properly by travis.
To test this hypothesis, I changed the name of the script called by travis. As expected, I got an error saying that travis can't find the file. So at least, I know that this line of code causes travis to look up at an sql file.
- mysql -u root --default-character-set=utf8 koalatest < backend/koalacal-backend/koalacal.sql
That being said, I have no idea if the file is run properly on the database.
For the sake of putting all relevant informations in this post, here is a link to the database script.
2- The tests can't connect properly to the database.
Here is the config file that contain the info regarding which database to connect to:
TestInstance=true
user=root
password=
serverName=localhost
databaseName=koalacal
portNumber=3306
testUser=root
testPassword=
testServerName=127.0.0.1
testDatabaseName=koalatest
testPortNumber=3306</code>
If the parameter TestInstance is set to true, the tests take the informations testUser, testPassword, testServerName, testDatabaseName and testPortNumber to connect to the relevant database.
I believe the connection informations currently contained in the config file match how the travis documentation says we need to connect to a mysql database. I tried to change the testUser to something invalid (like root3) and got error messages as expected.
Maybe somehow the tests can't connect to the database and don't produce a related error message, but I doubt it.
Can someone look at my problem and see if I've missed something obvious (or not)? I don't know what else to try and I don't want to be blocked one more week on a technical issue.
For anyone who may google travis mysql and has a similar error to the one I had, I solved my problem.
The error was caused by a case sensitivity issue. The java code tried to connect to tables like 'Calendar' and 'Event' while the sql script created the tables 'calendar' and 'event'.
It took a long time to troubleshoot this because the case sensitivity didn't pose any problem on my machine. Maven can run its tests properly without any issue. It's only on the travis servers that case sensitivity of the tables started to matter.

Can't connect to MySQL database: No suitable driver found

I'm having some troubles with java and jdbc.
In particular, while my code perfectly works in a NetBeans project, when i try to execute it on a terminal or on my ubuntu vps (which is where i need it to work) i always get this exception:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/quakes
First thing first: yes, i'm adding the jdbc .jar to the execute command and the compile command; Yes, i've even tried to add
Class.forName("com.mysql.jdbc.Driver");,
but I always get a ClassNotFoundException: com.mysql.jdbc.Driver exception
The .jar i'm using is the exact same that i use in the NetBeans project, so i know i have the right thing, and even downloading it again from the official site won't change a thing.
Yes, the database exists, and the result doesn't change if i try to connect to another db.
I also tried switching to postgresql (yes, i didn't forget to change the url), but to no avail, it still can't find the driver.
With this, i'm guessing that the actual error is in the compile/execute commands, but even them should be ok:
javac *.java <-cp mysql-connector-java-5.1.41-bin.jar > (the <> parenthesis means that i tried compiling with and without specifying the classpath);
java TAW -cp mysql-connector-java-5.1.41-bin.jar,
In case you want to see it, here's the method that tries to connect to the database:
public Connection getConnection() throws SQLException {
if (conn == null) {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+
this.dbname,this.user,this.pass);
}
return conn;
}
Does anyone have any idea on why this happens?
You need to put the classpath option for java before the name of your main class, otherwise it is regarded as program arguments:
java -cp mysql-connector-java-5.1.41-bin.jar;. TAW
You can use this method step by step to create connetion.
it is an example connectivity:
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://localhost/feedback?"
+ "user=sqluser&password=sqluserpw");

Categories