Showing posts with label postgres. Show all posts
Showing posts with label postgres. Show all posts

Monday, March 21, 2016

Fix Unsupported major.minor version

Source: stockoverflow

Sometimes when you build your project with wrong java version and run your project, you get this kind of error, below is a guide to what java version is needed when this error occurs...

The version number shown describes the version of the JRE the class file is compatible with.
The reported major numbers are:
J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

Source: stockoverflow postgres
If you encounter this error, PostgreSQL unsupported major.minor version
java.lang.UnsupportedClassVersionError: org/postgresql/Driver : Unsupported major.minor version 51.0 (unable to load class org.postgresql.Driver)

This means that the postgres driver you're using does not support the java version used to build your project.

You can check here in postgres documentation the jdbc version you need if you're running a certain java version: https://jdbc.postgresql.org/download.html

Below are the details found in this page...

If you are using the 1.6 then you should use the JDBC4 version. If you are using 1.7 then you should use the JDBC41 version. If you are using 1.8 then you should use the JDBC42 versionIf you are using a java version older than 1.6 then you will need to use a JDBC3 version of the driver, which will by necessity not be current

Sunday, January 25, 2015

SQL Notes: Problem using LIMIT in your code?

I want to get only the first row of my select SQL.
Why? Because I wanted to get the max of the alpha numeric document number system.
The best way to do that (but this depends on the pattern) to a document number with good pattern like ABCXXXXX01 (X stands for digits), is to order it by DESC.

Problem is it's going to return a bunch of results, so instead of creating another method just to do that, why not limit the result to 1? The only problem is I'm ecountering this LIMIT error in PostgreSQL. So I have to find another way to fetch this 1 row.

So below are other ways to get that 1 row (data below are from: freedb2)
For example, in Microsoft SQL Server you would use TOP:
SELECT TOP 10 column FROM table
MySQL and PostgreSQL SQL would use LIMIT like so:
SELECT column FROM table LIMIT 10
PostgreSQL v8.3 and later can also use this more standard SQL:
SELECT column FROM table FETCH FIRST 10 ROWS ONLY
An Oracle programmer would write
SELECT column FROM table WHERE ROWNUM <= 10
In Sybase, you would set rowcount
SET rowcount 10
SELECT column FROM tablez
So obviously, what worked for postgres is FETCH FIRST instead of LIMIT.
Now, I'm good. I've used this sql in Adempiere code. :)
Just spreading this good documentations from FreeDB2.