Wednesday, May 22, 2013

org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter

I was getting this error from Jasper server when leaving datetime input control blank:


Error Message

org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $3

Error Trace

org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $3 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) at 

Where clause in the query for java.sql.Timestamp column was like this:
and (time_col > $P{inputStartCreatedDate} or $P{inputStartCreatedDate} is null)

The solution is to add explicit type conversion like this:
and (time_col > $P{inputStartCreatedDate} or $P{inputStartCreatedDate}::timestamp is null)


Thursday, February 21, 2013

Calculation type issue in iReport

I was creating a variable in iReport and requested calculation type didn't work, I was just getting the value of the field. The cause of this turned out to be the wrong variable class for the variable. I.e. java.lang.String instead of java.lang.Double.

Thursday, December 13, 2012

How to update one or several classes in jar or ear file without doing full build

Sometimes you would like to update just one or several classes in jar or ear archive which is created in some lengthy build process and you do not want to do that full build.

In this example I want to update Yourclass.class class file inside Yourjar.jar jar file and then update it inside Yourear.ear ear file. The class file is already built by your IDE in bin folder in this path:

C:\<path to project>\bin\com\<package path>\Yourclass.class

Copy your jar and ear file to some temporary work folder c:\temp.

First, we will copy the class file with its package path to some temporary folder c:\temp because jar packaging tool will not let you to specify exact target path/folder. Second, we will use jar tool to repackage.


xcopy /Y "C:\<path to project>\bin\com\<package path>\Yourclass.class" c:\temp\com\<package path>\Yourclass.class

jar uf Yourjar.jar com\<package path>\Yourclass.class

jar uf Yourear.ear Yourjar.jar

Thursday, November 8, 2012

java.lang.ClassNotFoundException when running a JUnit test


If you get this error when running a JUnit 3 or 4 test in Eclipse:

java.lang.NoClassDefFoundError: <your unit test class name>
    at java.lang.ClassLoader.defineClass1(Native Method)
 ...
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

I've tried cleaning and building projects, restarting Eclipse and other suggested things to do in this case.

It turned out that errors in the project were responsible for that error. The project has another project with JRE specified incorrectly. As soon as I fixed this, unit test worked, even though the project still had some errors.

Monday, October 22, 2012

How to export java class or java resource from Oracle database

If you need to export java class or java resource loaded to Oracle database with loadjava use this:

1) get fully qualified name of a class/resource:


SELECT DBMS_JAVA.longname (object_name), user_objects.*
  FROM SYS.user_objects
 WHERE object_type IN ('JAVA CLASS', 'JAVA RESOURCE')

2) use DBMS_JAVA.export_resource or DBMS_JAVA.export_resource accordingly. This example outputs first 4000 chars only but you get the idea once you have the BLOB:

DECLARE
   v_blob      BLOB;
   stringvar   VARCHAR2 (4000);
BEGIN
   DBMS_LOB.createtemporary (v_blob, TRUE, DBMS_LOB.SESSION);

   --dbms_java.export_class( 'com/mysource/MyClass', v_Blob ) ;

   DBMS_JAVA.export_resource ('resources/resource.xml', v_blob);
   stringvar := UTL_RAW.cast_to_varchar2 (DBMS_LOB.SUBSTR (v_blob, 4000, 1));
   DBMS_OUTPUT.put_line (stringvar);
END;

Execute DDL statement over dynamic DB link


If you want to execute DDL statement <sql_statement> over DB link <db_link_name> try using this:


  DECLARE
    t_cursor PLS_INTEGER;
  BEGIN
    t_cursor := dbms_sql.open_cursor'||db_link_name||';
    dbms_sql.parse'||db_link_name||'(t_cursor, '''||sql_statement||''', dbms_sql.NATIVE);
    dbms_sql.close_cursor'||db_link_name||'(t_cursor);
  END;

This solution is quite tricky and I guess this wouldn't work for every DDL statement but it worked for me in 10g for enabling/disabling constraints and indexes. Another good thing about it is that DBlink name is dynamic and not hard-coded.

Search for a string in files in SunOS

The problem seems to be very easy to google for but many options for grep I was able to find didn't work for me. So if you want to get a list of file names containing some specific string in SunOS or Solaris you can use this command:

find . -type f | xargs grep -l "<string to search>"

use this if you want to ignore access/file read errors:

find . -type f 2>/dev/null | xargs grep -l "<string to search>"  2>/dev/null