cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic query sqlj

Former Member
0 Kudos

Is it possible to use dynamic query sqlj in netweaver developer studio sp15?

Thanks in advance,

Ruben

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Rubens code is right, but it uses an SQLJ implementation from Oracle. As I know SAP's SQLJ implementation doesn't support dynamic statements ('cause of db independence).

One little hint, always use plain old JDBC if you have to work with dynamic sql (with my experience it's the only thing that's works, ... most time )

regards,

daniel

Former Member
0 Kudos

There is not possible making dynamic sqlj query but you can cast sqlj to normal sql like


String sql = "..."; //"dynamic sqlj"

SqljIterator itr = null;
java.sql.Connection conn;
ConnEcat context = new ConnEcat(); //sqlj connection
conn = context.getConnection(); 

java.sql.Statement stmt = conn.createStatement();
java.sql.ResultSet rs = stmt.executeQuery(sql);
#sql itr = { CAST :rs };  


//close everithing

Be careful to fields in select fit with iterator

Regards

Vedran

Former Member
0 Kudos

Hi Vedran

Version 9i of SQLJ allows to embed both static and dynamic SQL statements in your SQLJ programs:

int id = 1;

String first_name = null;

String last_name = null;

String phone = null;

String table = "customers";

String query = "id = " + id;

String column = "first_name";

#sql , last_name, phone

INTO

:first_name, :last_name, :phone

FROM

:

WHERE

:

};

which is the version of sqlj in netweaver developer sp15?.

Regards

Ruben

Former Member
0 Kudos

I sow that syntax (in sqlj manuals, not in NW) and try implemented but never success. When I must have dynamic sql I use a way I send before.

BDW. I think, in next project I’ll use "classic" sql

Former Member
0 Kudos

Hi Ruben,

You can create SQLJ source files in projects where the creation of Java sources is allowed. You can either use the wizard to create an SQLJ source file or convert a Java source file to an SQLJ source file.

Please be ensutre that you have added the sqljapi.jar to the build path of your project. You can also use wizard for that.

1. Choose File -> New -> Other….

2. Choose Persistence ® SQLJ source.

3. Choose Next.

4. Enter the required information as if for a normal java file.

5. Choose Finish.

Thanks and Regards

Vishal Kumar