cancel
Showing results for 
Search instead for 
Did you mean: 

Insert Data Error WebDynpro MAXDB

former_member182416
Active Contributor
0 Kudos

Hi

I have a table in MAXDB which uses a Sequence to generate

unique nos for the records.


CREATE SEQUENCE  Z_DOCU_EXCHANGE_SEQ
START WITH 1
INCREMENT BY 1

When i run a insert statement through SQL Studio the record gets inserted properly.



INSERT INTO Z_DOCU_EXCHANGE VALUES(Z_DOCU_EXCHANGE_SEQ.NEXTVAL,
'A','B','C')

when i try the same through WebDynpro the record does not get inserted.

i am using the following String


String strInsert="INSERT INTO Z_DOCU_EXCHANGE VALUES(Z_DOCU_EXCHANGE_SEQ.NEXTVAL,'A','B','C')";

Is there any special syntax to use MAXDB Sequence in SQL Statement

through WebDynpro ?

Regards

Rajendra

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi RajendraKumar,

Try using this:

java.sql.PreparedStatement ps =

//Here con is your connection object.

con.prepareStatement("insert into Z_DOCU_EXCHANGE VALUES " +

"(<field1>, <field2>, <field3>, <field4>) " +

"values (?, ?, ?, ?)");

try {

ps.setInt (1, Z_DOCU_EXCHANGE_SEQ.NEXTVAL);

ps.setString(2, "A");

ps.setString(3, "B");

ps.setString(4, "C");

ps.executeUpdate();

} finally {

ps.close();

}

Regards,

Murtuza

former_member182416
Active Contributor
0 Kudos

Hi There

Thanks for the Help.

But

ps.setInt (1, Z_DOCU_EXCHANGE_SEQ.NEXTVAL);

wont work as Z_DOCU_EXCHANGE_SEQ.NEXTVAL is not known to web dynpro.

setInt expects integer value.

and it throws Compile Time Error .

Regards,

Rajendra

Answers (4)

Answers (4)

former_member182416
Active Contributor
0 Kudos

Hi All ,

The Problem was that the Sequence had to be executed on MAXDB

and i was trying to pass it as Query Parameter , which WebDynpro had no

idea.

The Problem was solved by using Stored procedure and

calling the sequence inside the same.

Thanks for your Suggesstions.

Regards

Rajendra

Former Member
0 Kudos

Hi

Do this

String x=Integer.toString(Z_DOCU_EXCHANGE_SEQ.NEXTVAL);

ps.setInt (1, Integer.parseInt(x));

Regards

Abhijith YS

Former Member
0 Kudos

Hi

you can convert it into int using

Integer.parseInt(Z_DOCU_EXCHANGE_SEQ.NEXTVAL ) if its a String

what is the return type of Z_DOCU_EXCHANGE_SEQ.NEXTVAL

Regards

Abhijith YS

former_member182416
Active Contributor
0 Kudos

Hi

Z_DOCU_EXCHANGE_SEQ.NEXTVAL gives the next number in the sequence.

Return type of Z_DOCU_EXCHANGE_SEQ.NEXTVAL is int

but this is supposed to execute on MAXDB.

thats why it works when executed thru SQL Studio.

Former Member
0 Kudos

Hi Rajendra,

If you are always going to insert data from WD then you can keep a counter in WD itself.

Regards,

Murtuza

Former Member
0 Kudos

Hi please find little correction with the above code

java.sql.PreparedStatement ps =

//Here con is your connection object.

try {

con.prepareStatement("insert into Z_DOCU_EXCHANGE VALUES " +

"(<field1>, <field2>, <field3>, <field4>) " +

"values (?, ?, ?, ?)");

ps.setInt (1, Z_DOCU_EXCHANGE_SEQ.NEXTVAL);

ps.setString(2, "A");

ps.setString(3, "B");

ps.setString(4, "C");

ps.executeUpdate();

}catch(SqlException sql){}

catch(Exception ex){}

finally {

try{

ps.close();

}

catch(Exception e){}

}

Regards

Abhijith YS