tags:

views:

43

answers:

2
+1  Q: 

SQLJ VS JAVA files

Hi! Can anyone expalain difference between .sqlj and .java files?

Best regards!

A: 

Wikipedia explains this.

A .java file is a normal Java source code file. An .sqlj file is a Java source code file with embedded SQL statements. You have to pass .sqlj source files through a preprocessor to make normal .java files from them, which you can then compile with a standard Java compiler.

Jesper
but if I use Select statement in .java file then i also use SQL statements in .java. Why I need .sqlj?
Debuger
You cannot add a `SELECT` statement directly in a Java source file. You'd have to make a `Statement` object, pass the query as a string etc. SQLJ makes it so that you can put SQL statements directly in your source file, without a lot of boilerplate code. The preprocessor will add the boilerplate code for you. Look at the Wikipedia page, it shows an example.
Jesper
Can You please say, where in real life we use SQLJ classes and why? In real applicationsor so on?Best regards, Kristaps
Debuger
I don't think that in practice there are many people who use SQLJ; I've never encountered it myself in more than 10 years of programming in Java. It's not a widely used way to use SQL from Java. There are other technologies, such as plain JDBC, or ORM frameworks such as Hibernate, which are much more common.
Jesper
+1  A: 

From the wikipedia article:

Whereas JDBC provides an API, SQLJ consists of a language extension. Thus programs containing SQLJ must be run through a preprocessor (the SQLJ translator) before they can be compiled.

aioobe